Inertia

Inertia ( int length );

Description

Draws the linear regression curve using the least-squares method to approximate data for each set of bars defined by the length parameter. The resulting interpolation function for each set of bars is defined by equation: y = a * current_bar + b . See the following example for details.

Input parameters

Parameter Default value Description
data - Defines the variable for which the linear regression curve is calculated.
length - Defines the period on which the approximation method is applied.

Example

script inertiaTS {
input y = close;
input n = 20;
def x = x[1] + 1;
def a = (n * Sum(x * y, n) - Sum(x, n) * Sum(y, n) ) / ( n * Sum(Sqr(x), n) - Sqr(Sum(x, n)));
def b = (Sum(Sqr(x), n) * Sum(y, n) - Sum(x, n) * Sum(x * y, n) ) / ( n * Sum(Sqr(x), n) - Sqr(Sum(x, n)));
plot InertiaTS = a * x + b;
}

input length = 20;
plot LinReg1 = Inertia(close, length);
plot LinReg2 = InertiaTS(close, length);

Draws the linear regression plot for the close value for the defined set of bars.