MAD (Mean Absolute Deviation)
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
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 20 | Rolling window size. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| values | number | null | Computed value at each bar; null before the warmup period completes |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
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.