LinRegArray2 (Function)
Linear Regression is a concept also known as the "least squares method" or "best fit." 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 two arrays (one with independent values and the other with dependent values) and calculates 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
LinRegArray2(IndepArray, DepArray, Size, TgtPos, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw)
Parameters
|
Name |
Type |
Description |
|
IndepArray |
NumericArray |
Specifies the numeric array of independent price points to evaluate. |
|
DepArray |
NumericArray |
Specifies the numeric array of dependent price points to evaluate. |
|
Size |
Numeric |
Specifies the number of array elements to consider in the regression calculation |
|
TgtPos |
Numeric |
Represents the number of bars into the future or back into the past, zero for the current bar. Use a positive integer for a previous point and a negative integer for a future point. |
|
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 intercept value at which the linear regression line will intersect the y-axis.. |
|
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. |
Returns
LinRegArray2 always returns 1. It calculates the linear regression line and passes the slope, angle, intercept and associated value by reference back to the calling function or technique.
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.
See Multiple Output Function for more information on using output parameters to return values.
Example
Assigns to Value2 the slope of a linear regression line, Value3 the angle, and Value4 the intercept point, and Value5 the projected intercept point from values in myArray. Value1 is assigned a value of 1:
Array: myArray1[20](0), myArray2[20](0);
Vars: oLRSlope(0), oLRAngle(0), oLRIntercept(0), oLRValueRaw(0);
{… add EL statements here to assign High values to array elements... }
Value1 = LinRegArray2 (myArray1, myArray2, 20, 5, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw);
Value2 = oLRSlope;
Value3 = oLRAngle;
Value4 = oLRIntercept;
Value5 = oLRValueRaw;