Bollinger Mean Reversion EA
Entering the instant price touches a band trades every minor poke through the extreme, most of which keep going. Waiting for a close back inside the band - confirming the reversion has actually started rather than merely that price reached the edge - is the standard refinement, and the one used here: the signal needs Close[2] outside the band and Close[1] back inside it. The take profit is the basis line, the middle Bollinger band, because that is literally the mean this trade is betting price reverts to. It is captured once at the moment of entry and sent as an ordinary hard take profit on the order, not recalculated and trailed bar by bar - a genuine reversion target, still protected by the broker if the terminal disconnects before it is reached. If the basis has moved to a price that would make a nonsensical target for the direction of the trade, the entry is skipped outright rather than sent with a broken order. A hard pip stop protects the position in case the reversion fails and price keeps trending through the band instead of returning to the mean. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the stop distance, using MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - Mean reversion assumes the range holds. In a strong trend the bands widen and walk with price rather than reverting, and the protective stop will be hit more often than the basis target in those conditions. - The basis target is fixed at entry, not trailed, so a basis that has moved substantially by the time price arrives will not be chased. - Signals are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Requires AutoTrading enabled (IsTradeAllowed() on MQL4, the three-way check described above on MQL5); if trading is disabled the EA logs it and skips the entry. - On an MQL5 netting account specifically: if a foreign-magic position already exists on the chart symbol, this EA refuses to open a new one rather than merge into it - see MQL4 VERSUS MQL5 DIFFERENCES above.
Expert advisor · MT5 · v1.0 · Free
About Bollinger Mean Reversion EA
Bollinger Mean Reversion EA is an expert advisor (trading robot) for MetaTrader 5 based on Bollinger Bands. It can size trades from your balance and risk percent. It has 10 settings, such as Bands period, Bands deviation and Stop loss pips. MQL source code included.
Files in the download: BollingerReversionEa.ex5, BollingerReversionEa.mq5, BollingerReversionEa.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 |
|---|---|---|
| Bands period | 20 | Bollinger Bands period |
| Bands deviation | 2.0 | Bollinger Bands standard deviation multiplier |
| Stop loss pips | 50 | Protective stop loss distance, in pips |
| 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 | 20260805 | 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 · Buy/Sell Arrows · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code