【LinRegArray】
[code]inputs:PriceValueArray[MaxSize]( numericarray ),
Size( numericsimple ),
TgtPos( numericsimple ),
oLRSlope( numericref ),
oLRAngle( numericref ),
oLRIntercept( numericref ),
oLRValueRaw( numericref ) ;
variables:
var0( 0 ),
var1( 0 ),
var2( 0 ),
var3( 0 ),
var4( 1 / 6 ),
var5( 0 ) ;
if Size > 1 then
begin
var2 = Size * ( Size - 1 ) * .5 ;
var3 = Size * ( Size - 1 ) * ( 2 * Size - 1 ) * var4 ;
var5 = Square( var2 ) - Size * var3 ;
var0 = 0;
for Value1 = 1 to Size
begin
var0 = var0 + ( Value1 - 1 ) * PriceValueArray[Value1] ;
end ;
var1 = SummationArray( PriceValueArray, Size ) ;
oLRSlope = ( Size * var0 - var2 * var1) / var5 ;
oLRAngle = ArcTangent( oLRSlope ) ;
oLRIntercept = ( var1 - oLRSlope * var2 ) / Size ;
oLRValueRaw = oLRIntercept + oLRSlope * ( Size - 1 - TgtPos ) ;
LinRegArray = 1 ;
end
else
LinRegArray = -1 ;
[/code]
页:
[1]