Skip to content

Free MT5 Expert Advisor

Bollinger Reversion EA

MT5 Expert Advisor that fades a close back inside the Bollinger Bands after a close outside, with the middle band as its target.

Mean reversionv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Stop-loss on every trade
Strategy
Buys when a bar closes back inside the lower Bollinger Band after the previous bar closed below it, and sells on the mirror setup at the upper band. The take-profit is the middle band.
Risk model
1% of balance per trade (configurable), stop-loss beyond the excursion on every order, one position at a time

What it does

Bollinger Reversion EA looks for a stretch that has already started to fail. A single close outside a band is not enough: the EA waits for the next bar to close back inside the band, then trades back toward the middle band.

This re-entry rule filters out many of the moves that keep walking along the band during a strong trend, because those bars never close back inside.

How it works

The bands are a 20-period simple moving average (middle band) plus and minus 2 standard deviations of the close. On every new bar the EA checks the last two closed bars:

  • Buy: the older bar closed below the lower band, and the last closed bar closed above the lower band but still below the middle band.
  • Sell: the older bar closed above the upper band, and the last closed bar closed below the upper band but still above the middle band.
  • Stop-loss: beyond the lowest low (buy) or highest high (sell) of the two bars, plus 0.5 × ATR(14).
  • Take-profit: the middle band value on the signal bar.

Two safety checks follow. If the stop would be wider than 3 × ATR the setup is skipped, and if the middle band is closer than 0.7 × the stop distance the setup is skipped because the reward would be too small. The Bollinger Bands lesson explains the band calculation in more detail.

How to use it

Reversion to the middle band works best in sideways or gently trending markets. H1 is a sensible starting point for major pairs. Many traders run it only during the more liquid hours, which the trading-hours inputs allow. Confirm your lot sizes with the Lot Size Calculator before running it.

Settings

InputDefaultWhat it changes
Bollinger period20Length of the middle band and deviation
Bollinger deviation2.0How far the bands sit from the middle
Stop buffer (x ATR)0.5Room beyond the excursion
Max stop (x ATR)3.0Skips very wide setups
Min reward vs stop0.7Skips setups with a close target
ATR period14Volatility used for stops and management
Risk per trade / Fixed lots1.0% / 0Position sizing
Max spread (points)30Spread filter
Trading start / end hour7 / 20Server-time window
Break-even / Trailingon / offStop management

Limitations

Breakouts that pause for one bar can still trigger a re-entry signal and then continue against the trade. The target is fixed at entry, while the live middle band keeps moving. On low timeframes the spread becomes a large share of the expected move. The rules contain no news filter, so scheduled releases can cause gaps through the stop.

Before you run it live

Test it in the Strategy Tester with realistic spreads, preferably on "every tick based on real ticks" data, and then on a demo account. Check that your broker's stop level is smaller than the stops the EA calculates, set the trading hours in server time, and keep risk per trade modest. Past behavior does not guarantee future results.

Key inputs

Key inputs of Bollinger Reversion EA
InputDefaultDescription
Bollinger period20Bars used for the middle band and the standard deviation.
Bollinger deviation2.0Band width in standard deviations.
Stop buffer beyond the excursion extreme (x ATR)0.5Extra room added beyond the low or high of the two signal bars.
Skip if the stop is wider than this (x ATR)3.0Rejects setups whose stop would be unusually wide.
Skip if distance to the middle band < this x stop0.7Minimum reward relative to risk.
Risk per trade (% of balance)1.0Lot size is calculated from the stop distance and this percentage.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors