Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
The Baseline Excursion Reversion strategy is a mean-reversion system built around an EMA (Exponential Moving Average) baseline and an ATR (Average True Range) volatility filter. In plain terms, it treats a slow-moving average of price as a "fair value" anchor and looks for moments when price has wandered unusually far from that anchor — a stretch the strategy calls an excursion — before betting that the elastic band snaps back toward the middle.
What separates this approach from a naive "price is far from the average, so fade it" idea is its emphasis on structure and regime. An excursion here is defined as a continuous run of bars that stay on one side of the baseline, regardless of whether each individual candle ticks up or down. The strategy measures both how long that run has persisted and how deeply it penetrated, scaling that depth by ATR so the distance is expressed in units of volatility rather than raw price. It only acts when the excursion begins curling back toward the baseline — and, critically, only when the baseline itself is roughly flat.
As a learning tool, Baseline Excursion Reversion is well suited to traders who want to study counter-trend, mean-reversion mechanics and the importance of regime filtering. It deliberately avoids fading strong trends, since an over-extension in the direction of a trend is often the trend itself rather than exhaustion. This makes it a useful case study in how volatility scaling, persistence counting, and a trend-slope gate can be combined into a single disciplined ruleset. It is designed for range-bound or balanced market conditions, not for chasing breakouts.
How It Works
The strategy processes one fully closed bar at a time on a single timeframe. It maintains an EMA baseline of the close, a simple-mean ATR for volatility scaling, and a running record of the current excursion.
Building the excursion:
- Each closed bar is compared to the EMA baseline. If the close is above the baseline, the bar belongs to a bullish excursion; if below, a bearish excursion.
- As long as consecutive bars remain on the same side, the strategy increments the excursion length and tracks the peak penetration — the deepest
|close − baseline| ÷ ATRreached — plus the highest High and lowest Low of the run. - If price crosses to the other side of the baseline, the excursion resets and a new one begins.
The regime gate (a key filter):
- Before any trade, the strategy measures the baseline's slope over the
SlopeLookbackperiod, normalized by ATR. - If that normalized slope exceeds
MaxTrendSlope, the market is considered to be trending and no trade is taken. The strategy only fades excursions when the baseline is roughly flat.
Entry conditions:
- The excursion must have persisted for at least
MinExcursionBarsbars. - Its peak penetration must be at least
EntryStretchATRs — confirming price stretched unusually far from fair value. - The most recent closed bar must show a curl-back:
- For a bullish excursion (price above baseline), the strategy signals a SELL when the newest bar is bearish (close below its open) and closes below the prior bar's close.
- For a bearish excursion (price below baseline), the strategy signals a BUY when the newest bar is bullish (close above its open) and closes above the prior bar's close.
Take-profit logic:
- The take-profit is the baseline itself — the mean the strategy expects price to revert to. The trade is only taken if that target sits at least
MinRewardAtrATRs away from entry, filtering out setups with too little room to run.
Stop-loss logic:
- The stop is placed just beyond the excursion's structural extreme (the peak High for a short, the trough Low for a long), buffered by
BufferAtr × ATR. This anchors risk to the actual reversal structure rather than an arbitrary distance.
Trade management overlay:
- The strategy holds one position per magic number at a time.
- If an open position's bar closes back across the baseline — meaning the mean has effectively been reached — the position is closed early, without waiting for the take-profit.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| MaPeriod | 20 | 5 | 60 | EMA period for the fair-value baseline that price reverts toward. |
| AtrPeriod | 14 | 5 | 40 | ATR period used to volatility-scale penetration depth and size stops. |
| MinExcursionBars | 5 | 2 | 20 | Minimum bars the excursion must persist on one side of the baseline. |
| EntryStretch | 2.0 | 1.0 | 4.0 | Minimum peak penetration (in ATRs) required to qualify as over-extended. |
| MaxTrendSlope | 1.0 | 0.2 | 3.0 | Flat-regime gate: the baseline's ATR-normalized slope must stay below this. |
| SlopeLookback | 10 | 3 | 40 | Number of bars back used to measure the baseline slope for the regime gate. |
| BufferAtr | 0.5 | 0.0 | 2.0 | Stop buffer beyond the excursion's structural extreme, as a multiple of ATR. |
| MinRewardAtr | 0.6 | 0.2 | 3.0 | Minimum distance (in ATRs) from entry back to the baseline for a trade to qualify. |
| Lots | 0.10 | 0.01 | 1.0 | Position size in lots. |

Recommended Chart Settings
Baseline Excursion Reversion is a single-timeframe strategy — every calculation reads from the chart's primary timeframe. Because it is a mean-reversion system that depends on price oscillating around a stable average, it tends to be studied on liquid instruments during range-bound conditions.
A common starting point is a major forex pair (such as EUR/USD or GBP/USD) on an intraday timeframe like H1 (1-hour), where mean-reversion behavior around a moving average is often easier to observe. The default parameters (20-period EMA, 14-period ATR) are general-purpose values, not optimized for any specific market. You are encouraged to test the strategy across several symbols and timeframes on a demo account, since results will vary considerably with volatility, spread, and prevailing market conditions. What works in a quiet, ranging session may behave very differently during trending or high-impact-news periods.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
Strengths of the approach. The strategy's design reflects several sound principles worth studying. It scales distance by volatility (ATR) rather than using fixed pip thresholds, so it adapts to changing market conditions. It refuses to fade strong trends thanks to its flat-regime slope gate — a common failure mode of naive mean-reversion systems is that they short every rally in an uptrend. By requiring a curl-back candle, it waits for evidence that the stretch is releasing rather than still extending, and by anchoring the stop beyond the excursion's real high or low, it ties risk to genuine structure.
Known limitations. Mean-reversion strategies are, by nature, vulnerable to sustained directional moves. Even with a slope filter, a market can transition from flat to trending after a position is opened, and a fade that "should" revert can instead run against the stop. The take-profit is fixed at the baseline, which may sit close to entry when the EMA has drifted toward price — the MinRewardAtr filter mitigates but does not eliminate low-reward setups. The strategy also trades only one position at a time per magic number, so it may sit idle for long stretches waiting for a qualifying excursion.
Where it may underperform. Strong, persistent trends, breakout regimes, and choppy news-driven volatility can all produce excursions that keep extending rather than reverting. Wide spreads on exotic pairs or during illiquid hours can erode the relatively modest reward targets. As with any counter-trend method, the strategy may experience clusters of losses when the market's character shifts. Treat it as a framework for learning about regime-aware mean reversion, not as a finished, market-ready system.
Risk Management Tips
Sound risk management matters far more than any single entry rule. Consider the following general principles:
- Position sizing: Keep each trade small relative to your account. A widely cited guideline is to risk no more than 1–2% of account equity on any single position. Adjust the
Lotsparameter so the distance to your stop reflects that limit. - Use a demo account first: Test the strategy thoroughly in a risk-free demo environment before committing real capital. This lets you observe how it behaves across different symbols, timeframes, and market conditions.
- Understand drawdown: Every strategy experiences losing streaks. Study the depth and duration of drawdowns in testing so you are psychologically and financially prepared for them.
- Account for costs: Spreads, commissions, and slippage all reduce net results — especially for a mean-reversion system whose profit targets are modest. Include realistic costs in any evaluation.
- Never over-leverage: Leverage amplifies both gains and losses. Use it conservatively and understand your broker's margin requirements.
- Diversify your study: Avoid relying on a single strategy or instrument. Treat this EA as one component of a broader learning process, not a standalone solution.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: BaselineExcursionReversion.ex5 (14 downloads)
- Source Code: BaselineExcursionReversion.mq5 (14 downloads)
- Documentation: BaselineExcursionReversion.pdf (20 downloads)