{ Linear Regression multiple-output function, verified as series for backward compatibility; all outputs of this function are identical to the LinearReg function except for the LRValueRaw output, which in not adjusted for ExecOffset here (series functions cannot be adjusted this way); also MULTIPLE-OUTPUT FUNCTIONS note below } inputs: Price( numericseries ), Length( numericsimple ), { Length > 1 } TgtBar( numericsimple ), { use negative integer for future, positive for past } oLRSlope( numericref ), oLRAngle( numericref ), oLRIntercept( numericref ), { left intercept, at vertical through Price[ Length - 1 ] } oLRValueRaw( numericref ) ; variables: SumXY( 0 ), SumY( 0 ), SumX( 0 ), SumXSqr( 0 ), OneSixth( 1 / 6 ), Divisor( 0 ) ; if Length > 1 then begin SumX = Length * ( Length - 1 ) * .5 ; SumXSqr = Length * ( Length - 1 ) * ( 2 * Length - 1 ) * OneSixth ; Divisor = Square( SumX ) - Length * SumXSqr ; SumXY = 0; for Value1 = 0 to Length - 1 begin SumXY = SumXY + Value1 * Price[Value1] ; end ; SumY = Summation( Price, Length ) ; oLRSlope = ( Length * SumXY - SumX * SumY) / Divisor ; oLRAngle = ArcTangent( oLRSlope ) ; oLRIntercept = ( SumY - oLRSlope * SumX ) / Length ; oLRValueRaw = oLRIntercept + oLRSlope * ( Length - 1 - TgtBar ) ; LinearRegFC = 1 ; end else LinearRegFC = -1 ; { MULTIPLE-OUTPUT FUNCTIONS A multiple-output function has two types of parameters or "inputs" - input parameters and input/output parameters. The values of the input parameters are passed into the multiple-output function, but not modified by the function. The values of the input/ output parameters are passed into the multiple-output function, modified by it, and the modified values are then inherited by - or output to - the calling routine. The input/output parameters are often used for output purposes only, i.e., the incoming values are ignored. The outputs are in addition to the function return. In multiple-output functions, the function return is generally used to return an error code, though sometimes the return may simply be a dummy value. The input/output parameters are declared with a "ref" suffix (such as "numericref") in the multiple-output function's declaration statements. For further clarity, the names of the input/output parameters are generally prefixed with an "o" in the function as well as in all the routines that call the function. The built-in single-return WRAPPER FUNCTIONS that call the multiple-output functions are specialized calling routines designed to offer simplified, alternate pathways to the functionality of the underlying multiple-output functions. In the wrapper functions, the input/output parameters are declared as local variables and generally initialized to zero. They are passed through to the multiple-output function without further modification. After the call, the wrapper function picks out the single output of interest and assigns it as the return of the wrapper function. } { ** Copyright (c) 2001 - 2010 TradeStation Technologies, Inc. All rights reserved. ** ** TradeStation reserves the right to modify or overwrite this analysis technique with each release. ** }