Quantile Band Reversion
Bollinger-style bands describe a lookback window's spread with a mean and a standard deviation, which draws a symmetric envelope around the price regardless of what the window's actual distribution looks like. A window with a skew, a fat tail, or a lingering step-change from a prior trend has its true edges somewhere other than a symmetric band's edges - the band is drawn from an assumed shape, not the data's real one. This system instead sorts the closing prices in the lookback window and reads the upper and lower bands directly off the sorted array at the requested quantile ranks (e.g. the 90th and 10th percentile), using linear interpolation between the two bracketing order statistics - the standard "type 7" empirical quantile definition used by R's and numpy's default quantile functions. Whatever shape the recent price distribution actually has, skewed, fat-tailed, or bimodal, the bands sit where that data genuinely puts them. A touch of either band, plus a small ATR buffer so the very first tick past the band is not chased, triggers a fade back toward the window's empirical median (its 50th percentile) - the position closes once price reverts to that median rather than at a fixed take-profit distance that ignores where the distribution's centre currently sits. Notes and limitations - A market that trends persistently rather than reverting will walk the band outward and keep triggering fades against the trend; the fixed ATR stop is the backstop for exactly that scenario, not a rare edge case. - The bands recompute every bar from the trailing InpLookbackBars closes, so they adapt to a changing regime, but also mean a recent structural shift (a large gap, a step-change) widens or shifts the bands for the rest of that window's life. - Only one position is held at a time per chart/magic combination. - Requires AutoTrading enabled to open or close anything.
Expert advisor · MT5 · v1.0 · Free
About Quantile Band Reversion
Quantile Band Reversion is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It can size trades from your balance and risk percent. It has 13 settings, such as Lookback bars, Upper quantile and Lower quantile. MQL source code included.
Files in the download: QuantileBandReversion.ex5, QuantileBandReversion.mq5, QuantileBandReversion.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback bars | 100 | Bars in the rolling window the quantiles are computed from |
| Upper quantile | 0.90 | Upper band quantile (0-1), e.g. 0.90 = 90th percentile |
| Lower quantile | 0.10 | Lower band quantile (0-1), e.g. 0.10 = 10th percentile |
| Band buffer atr | 0.25 | Extra ATR buffer added beyond the band before fading, to avoid the very first touch |
| Atr period | 14 | ATR period used for the buffer and the stop |
| Stop atr multiple | 2.0 | Stop distance beyond entry = ATR * this multiplier |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260614 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Bollinger Bands · Channels & Envelopes · Trend · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code