LinRegArray (Function)
The LinRegArray function calculates the slope and angle of a linear regression line from an array of values and allows you identify the value where the projected line crosses a future (or past) array index position.
Syntax
LinRegArray(PriceArray, Size, TgtPos, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw)
Returns (Integer)
The oLRSlope, OLRAngle, OLRIntercept, and oLRValueRaw output parameters returns the slope, angle, intercept, and regression value. The LinRegArray function itself returns a value of 1.
Parameters
|
Name |
Type |
Description |
|
PriceArray |
NumericArray |
Specifies the numeric array of data elements to evaluate. |
|
Size |
Numeric |
Sets the number of elements (size) in the array to consider. |
|
TgtPos |
Numeric |
Sets the point in the past or future to use for projecting a regression value. Use a positive integer for a previous point and a negative integer for a future point. |
|
oLRSlope |
Numeric |
Outputs the slope of the linear regression line. |
|
oLRAngle |
Numeric |
Outputs the angle of the linear regression line in degrees. |
|
oLRIntercept |
Numeric |
Outputs the intercept value at which the linear regression line will intersect the last array element. |
|
oLRValueRaw |
Numeric |
Outputs the regression value for a point TgtPos elements in the past or projected into the future. |
Remarks
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.
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: myArray[20](0);
Vars: oLRSlope(0), oLRAngle(0), oLRIntercept(0), oLRValueRaw(0);
{… add EL statements here to assign High values to array elements... }
Value1 = LinRegArray (myArray, 20, 5, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw);
Value2 = oLRSlope;
Value3 = oLRAngle;
Value4 = oLRIntercept;
Value5 = oLRValueRaw;