DocsMathStatisticsMAD (Mean Absolute Deviation)

MAD (Mean Absolute Deviation)

Windowed · default period 20Statistics

The Mean Absolute Deviation node computes the average of the absolute deviations from the window mean: MAD = mean(|x − mean(x)|). Unlike variance, MAD uses absolute differences rather than squares, making it linearly proportional to deviations and less sensitive to extreme outliers. MAD is the spread measure used in the Commodity Channel Index (CCI) and a popular robust volatility estimate.

Algorithm

  • μ = mean(non-null window values)
  • MAD = mean(|v[i] − μ|) for all non-null v[i]
  • Returns null when no non-null values exist

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size.

Inputs & Outputs

PortTypeDescription
Inputs
inputnumber[]Source numeric array
Outputs
valuesnumber | nullComputed value at each bar; null before the warmup period completes
timestampsnumber[]Bar timestamps (UNIX ms), aligned 1-to-1 with values
Live mode: In live streaming mode the node updates only the last bar in-place rather than recalculating the full array, keeping CPU usage minimal during real-time data feeds.

Use Cases

CCI Construction

CCI = (price − SMA(price, n)) / (0.015 × MAD(price, n)) — connect price to both Average and MAD, then subtract and divide to replicate the Commodity Channel Index.

Robust Volatility

Use MAD as an alternative to standard deviation in regimes with frequent price spikes — MAD grows linearly with outliers while stddev grows quadratically.

Signal Normalization

Normalize an oscillator by dividing by its rolling MAD to create a Z-score-like series that is resistant to distortion by outlier bars.