Loading…

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 · MT4 · v1.0 · Free

About Bollinger Mean Reversion EA

Bollinger Mean Reversion EA is an expert advisor (trading robot) for MetaTrader 4 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.ex4, BollingerReversionEa.mq4, BollingerReversionEa.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Bands period20Bollinger Bands period
Bands deviation2.0Bollinger Bands standard deviation multiplier
Stop loss pips50Protective stop loss distance, in pips
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 number20260805Magic 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 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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 · Buy/Sell Arrows · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria