MeanDev

Function that returns the mean deviation of a series for a given period. It accepts the following parameters:

Parameter NameTypeDefault ValueNotes
applyToSeries<Number>--
periodNumber--

Returns: Series<Number>

MeanDev is a built-in function - you can use it directly. Below is an example implementation:

1 function MeanDev(applyTo, period):
2 average = SMA(applyTo, period)
3
4 sumOfDeviation = 0
5
6 for barIndex from 0 to (period - 1)
7 sumOfDeviation = sumOfDeviation + Math.Abs(applyTo[barIndex] - average)
8
9 sumOfDeviation / period