Loading…

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

SettingDefaultWhat it does
Lookback bars100Bars in the rolling window the quantiles are computed from
Upper quantile0.90Upper band quantile (0-1), e.g. 0.90 = 90th percentile
Lower quantile0.10Lower band quantile (0-1), e.g. 0.10 = 10th percentile
Band buffer atr0.25Extra ATR buffer added beyond the band before fading, to avoid the very first touch
Atr period14ATR period used for the buffer and the stop
Stop atr multiple2.0Stop distance beyond entry = ATR * this multiplier
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260614Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Bollinger Bands · Channels & Envelopes · Trend · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria