LinearRegFC (Function)
Linear regression attempts to fit a straight line between several data points in such a way that distance between each data point and the line is minimized.
This function uses a fast calculation method to determine the slope and angle of a linear regression line, and also determines the value of the line on the current bar or a specified number of bars ago or projected bars into the future.
Function
LinearRegFC(Price, Length, TgtBar, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw)
Parameters
Name |
Type |
Description |
Price |
Numeric |
Specifies the value of interest is to be used. |
Length |
Numeric |
Specifies the number of bars to consider in the regression calculation. |
TgtBar |
Numeric |
Represents the number of bars into the future or back into the past, zero for the current bar. Use a negative integer for a future bar, a positive integer for a previous bar, and zero for the current bar. |
oLRSlope |
Numeric |
Variable that receives the slope of the linear regression line. |
oLRAngle |
Numeric |
Variable that receives the angle of the linear regression line in terms of degrees. |
oLRIntercept |
Numeric |
Variable that receives the regression value for x number of bars out into the future or x number of bars back in the past. |
oLRValueRaw |
Numeric |
Variable that receives the regression value for x number of bars out into the future or x number of bars back in the past. The term "raw" in the name of this parameter refers to the fact that the value is not adjusted for the execution offset. See ExecOffset. See also the function LinearReg, in which the linear regression value is adjusted for execution offset. |
Returns
LinearRegFC returns 1, provided that the Length input's value is greater than 1. If the Length input's value is not greater than 1, the function will return -1 (negative 1).
The function calculates the linear regression line, then passes the slope, angle, intercept and linear regression line's value by reference back to the calling function, study, or strategy.
Usage
The equation of any line resembles the following:
y = mx + b
In the equation m refers to the slope of the regression line, b refers to the constant intercept of the y-axis, x is the independent variable, and y is the dependent variable. This function returns all values.
The input Price can be hard coded with a bar attribute such as Close, Open, High, Low, and Volume or a numeric series type input. It can also be replaced with a valid EasyLanguage expression. For example: Close + Open, or Average(RSI(Close,14),14).
The inputs Length and TgtBar can be hard coded replaced with numeric simple type inputs.
This function uses a fast calculation method that uses more memory than the traditional method.