Docs

ta.mad

Measure dispersion as the median distance from the median, which resists outliers.

itm
ta.mad(source, length, min=length)

Median absolute deviation about the window median: median(abs(source - median(source, length))). The robust twin of ta.dev, which is the mean absolute deviation about the mean. It is the raw deviation, not scaled by 1.4826, so multiply by 1.4826 for a normal-consistent estimate of sigma.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
sourceSeriesnumber--The series to read.
lengthConstantnumber-1 to 10000Window in observed bars.
minConstantnumber-1 to 10000Valid values the window must hold before it reports (an option, written min=15). An na is skipped. Absent = length: the window must be full and gap-free.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
length bars. Names in the warm-up are this operator’s parameters.
Missing values
Returns na until length consecutive non-na observations are in the window. An na resets the accumulation. With min=, an na is skipped and the value is taken over the valid observations once there are at least min of them.

Example

itm
ta.mad(close, 20)
itm
plot(ta.mad(close, 20), "Median deviation 20")