【LinearReg】
[code]inputs:PriceValue( numericseries ),
Len( numericsimple ),
TgtBar( numericsimple ),
oLRSlope( numericref ),
oLRAngle( numericref ),
oLRIntercept( numericref ),
oLRValue( numericref ) ;
variables:
var0( 0 ),
var1( 0 ),
var2( 0 ),
var3( 0 ),
var4( 1 / 6 ),
var5( 0 ) ;
if Len > 1 then
begin
var2 = Len * ( Len - 1 ) * .5 ;
var3 = Len * ( Len - 1 ) * ( 2 * Len - 1 ) * var4 ;
var5 = Square( var2 ) - Len * var3 ;
var0 = 0;
for Value1 = 0 to Len - 1
begin
var0 = var0 + Value1 * PriceValue[Value1] ;
end ;
var1 = Summation( PriceValue, Len ) ;
oLRSlope = ( Len * var0 - var2 * var1) / var5 ;
oLRAngle = ArcTangent( oLRSlope ) ;
oLRIntercept = ( var1 - oLRSlope * var2 ) / Len ;
oLRValue = oLRIntercept + oLRSlope * ( Len - 1 + ExecOffset - TgtBar ) ;
LinearReg = 1 ;
end
else
LinearReg = -1 ;
[/code]
页:
[1]