LinDev

LinDev ( int length );

Default values:

length: 12

Input parameters

Parameter Default value Description
data - Defines the variable for which the standard deviation is calculated.
length 12 Defines the period on which the standard deviation is calculated.

Description

Returns the linear deviation of data for the last length bars.

General Information

Linear deviation measures the average absolute difference between the mean and the current value.

Example

declare lower;
input length = 10;
plot LinearDev = LinDev(close, length);

The code draws the linear deviation plot for the current symbol for the defined number of bars.

Example 2

script LinDevTS {
input data = close;
input length = 12;
def avgData = Average(data, length);
plot LinDevTS = ( fold i = 0 to length with LD do LD + AbsValue(avgData - GetValue(data, i)) ) / length;
}

declare lower;

input length = 12;

plot LinDev1 = LinDev(close, length);
plot LinDev2 = LinDevTS(close, length);

In the example above, two plots are calculated, both showing the linear deviation of the close price over the last 12 bars. LinDev1 is calculated using the built-in function LinDev. LinDev2 is calculated using a thinkScript implementation of this function. Both plots form a single line on the chart.