Login Page - Create Account

Technical Studies Reference


Moving Linear Regression / Moving Average - Linear Regression

The Moving Linear Regression and the Moving Average - Linear Regression studies calculate and display the value of a linear regression function of the selected Input Data (Open, High, Low, Close) over the specified Length.

Therefore, any point along the Linear Regression study line is equal to the ending value of a Linear Regression line. For example, the ending value of a Linear Regression line that covers 10 closing prices will have the same value as a Moving Linear Regression line with a Length of 10 at the same bar.

For the calculation method, refer to the LinearRegressionIndicator_S function in the /ACS_Source/SCStudyFunctions.cpp file in the folder Sierra Chart is installed to. We give a detailed mathematical description of this method below.

If you draw a Linear Regression Chart Drawing over the same Length that you have set in the study Inputs for this study, then where that drawing ends, it will have the same value as the Moving Average - Linear Regression study.

Next we describe the calculation of the Linear Regression Indicator. Let \(n\) be the Input Length. Let \(T\) be the variable measured along the horiztonal axis, let \(X\) be a random variable denoting the Input Data, which is measured along the vertical axis. We denote the values of these variables at Index \(i\) as \(T_i = i\) and \(X_i\), respectively , where \(i\) runs from \(1\) to \(n\) in each calculation. We denote the Current Index Value as \(t\). The Linear Regression Indicator function computes each of the following sums for \(t \geq n - 1\). These sums are used to calculate the regression statistics.

\(\displaystyle{\sum_{i=1}^n {i} = \frac{n(n+1)}{2}}\)

\(\displaystyle{\left(\sum_{i=1}^n {i}\right)^2 = \frac{n^2(n+1)^2}{4}}\)

\(\displaystyle{\sum_{i=1}^n {i^2} = \frac{n(n+1)(2n+1)}{6}}\)

\(\displaystyle{\sum_{i=t-n+1}^t {X_i}}\)

\(\displaystyle{\sum_{i=t-n+1}^t{T_{i - t + n}X_i} = \sum_{i=t-n+1}^t{(i-t+n)X_i}}\)

For an explanation of the Sigma (\(\Sigma\)) notation for summation, refer to our description here.

Note: The sums over the \(T-\) values do not move, as the sums over the \(X-\) values do. This is compensated for by using the Length \(n\) in certain places instead of the current value \(t\) of the Index. This always gives the correct value of the LRI and of the slope of the regression line, but it does not give the correct value of the intercept.

These sums are used to compute the regression statistics for \(t \geq n - 1\), as shown below.

Slope:

\(\displaystyle{b_t(X,n) = \frac{n \cdot \sum_{i=t-n+1}^t{(i-t+n)X_i} - \frac{n(n+1)}{2} \cdot \sum_{i=t-n+1}^t {X_i}}{n \cdot \frac{n(n+1)(2n+1)}{6} - \frac{n^2(n+1)^2}{4}}}\)

Intercept:

\(\displaystyle{a_t(X,n) = \frac{\sum_{i=t-n+1}^t {X_i} - b_t(X,n) \cdot \frac{n(n+1)}{2}}{n}}\)

The regression model is of the form \(X = a_t(X,n) + b_t(X,n)\cdot T\).

Linear Regression Indicator:

The Linear Regression Indicator is the \(X-\)coordinate of the right endpoint of the linear regression trendline of Length \(n\). Its value \(LRI_t(X,n)\) at Index \(t\) for the given Inputs is calculated for \(t \geq n - 1\) as \(LRI_t(X,n) = a_t(X,n) + b_t(X,n)\cdot n\).

The Moving Average - Linear Regression and Moving Linear Regression are both mathematically identical to the Linear Regression Indicator for \(t \geq n - 1\). Their respective values at Index \(t\) for the given Inputs are denoted as \(LRMA_t(X,n)\) and \(MLR_t(X,n)\).

Inputs

Spreadsheet

The spreadsheet below contains the formulas for this study in Spreadsheet format. Save this Spreadsheet to the Data Files Folder.

Open it through File >> Open Spreadsheet.

Moving_Linear_Regression.104.scss


*Last modified Wednesday, 03rd January, 2018.