Sidechair

ta.dev()

Browse the reference

Returns the mean absolute deviation of source over length bars: the average distance of each value from the window's mean.

Try it in the editor

ta.dev finds the simple average of the window, then averages the absolute distance of every value from it. Unlike ta.stdev, distances are not squared, so outliers count less.

The window must be full and free of na for a value to appear.

Syntax

Pine Script
ta.dev(source: series int/float, length: series int) -> series float

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredThe series whose mean absolute distance from its own mean is measured over length bars.
lengthseries intrequiredNumber of bars in the window. A whole number of 1 or more.

Returns

series float: the mean absolute deviation in the units of source.

Remarks

  • ta.cci divides by 0.015 times this value.

Example

Pine ScriptMean deviation of priceOpen in editor
//@version=6
indicator("Mean deviation")
plot(ta.dev(close, 20), "Mean abs deviation", color = color.teal)
plot(ta.stdev(close, 20), "Stdev", color = color.gray)

See also

Runs on Sidechair