FUNCTION NAME: LINREG
STUB: result_vector = LINREG( input_vector, StartPoint, EndPoint )
Function LINREG calculates the Linear Regression Line of a vector.
The Linear Regression returns a vector that always represents a straight line. That line is calculated using the Least Squares method. That method essentially fits a line to the supplied data in such a way so the distance from all points in the source vector is minimized.
The linear regression is not calculated for the whole range of the vector but from StartPoint to EndPoint.
Also see
OUTLIERS
SLOPE
DELTA
Example
//
// Example of using LINREG and SLOPE
//
RANGE(-250,_LASTDATE)
CLOSE =LOAD(_TICKER,CLOSE)
VOLUME=LOAD(_TICKER,VOLUME)
// Interpolate for missing values
ICLOSE=INTERPOLATE(CLOSE)
// Calculate moving average
MA50 = MOVAVG(ICLOSE,50)
// Change size of matrix to get rid of missing values in MA50
RANGE(-200,_LASTDATE)
LINREG = LINREG(ICLOSE,160,200)
RANK1 = SLOPE(ICLOSE,160,200)
// Display on graph
GRAPHTITLE(_TICKER)
GRAPHAREA(75,25,0,0,0,0)
GRAPHLINE(Axis1,CLOSE,RED)
GRAPHLINE(Axis1,MA50,BLUE)
GRAPHLINE(Axis1,LINREG,GREEN)
GRAPHBAR(Axis2,VOLUME,GREEN)
..and here is the output..

