Median Absolute Deviation Bands
Bollinger Bands are built from the mean and standard deviation of the lookback window. Both of those statistics sum or square every point in the window, so one unusually large spike bar - a news wick, a thin-liquidity print - pulls the mean toward it and inflates the standard deviation in proportion to how far away the spike is, which widens and shifts the whole band on a single outlier bar. Median Absolute Deviation Bands replace both statistics with rank- based equivalents: the rolling median as the centre line, and the median of the absolute deviations from that median (the MAD) as the spread measure. Because both only care about where a value ranks within the window, not how large it is, a single extreme bar can move the median or MAD by at most one rank position - the band stays close to where it would have been without the spike, rather than being pulled toward it. An optional 1.4826 scale factor is applied to the MAD by default, which is the standard constant that makes MAD comparable to a normal distribution's standard deviation, so the default multiplier reads similarly to a familiar Bollinger multiplier. Notes and limitations - The median and MAD are recomputed by sorting the full window on every bar; this is deliberately simple and correct rather than an incrementally maintained running median, and is fast enough for any reasonable InpPeriod on a single-symbol chart. - On a strongly trending market the median lags the same way any rolling centre line does - the robustness this indicator adds is against outlier bars within the window, not against trend lag itself. - With an even-numbered InpPeriod the median and MAD are each the average of the two middle sorted values, per the standard definition; this is not configurable.
Indicator · MT5 · v1.0 · Free
About Median Absolute Deviation Bands
Median Absolute Deviation Bands is an indicator for MetaTrader 5. It has 3 settings, such as Period, Multiplier and Scale to sigma. MQL source code included.
Files in the download: MadBands.ex5, MadBands.mq5, MadBands.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Period | 20 | Rolling window for the median and MAD |
| Multiplier | 3.0 | MAD multiple offset from the median |
| Scale to sigma | true | Multiply MAD by 1.4826 so it approximates std dev under a normal distribution |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Bollinger Bands · Channels & Envelopes · News Trading · MT5 Indicator · MQL5 Source Code