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 Trimmed Mean Reversion Band is a mean-reversion strategy built around a trimmed mean — a robust statistical estimator of "fair value" — rather than the ordinary moving average that powers most reversion bands. A trimmed mean is calculated by taking a window of recent closing prices, sorting them, discarding a fixed percentage of the highest and lowest values, and averaging only the central core that remains. Because the outliers are thrown away entirely, a single spike bar or a violent news candle cannot drag the centre line around the way it would with a Simple Moving Average (SMA) or an Exponential Moving Average (EMA).
This matters because standard reversion tools — Bollinger Bands, Keltner Channels, envelopes, and disparity indexes — all anchor on estimators that outliers distort in two ways at once: the fat tails pull the centre off true value and inflate the band width, so genuine price stretches stop looking statistically extreme. By building both the centre line and the band half-width from the same trimmed core (using the standard deviation of that core for the spread), the strategy aims for a more stable anchor. That stability is the whole idea, and it is what the design intends to translate into smaller, more controlled drawdowns.
The Trimmed Mean Reversion Band is designed for ranging, sideways market conditions on liquid instruments — it was built and tuned with EURUSD in mind but can be studied on any liquid FX major or metal. It runs on a single primary timeframe. As a learning tool, it suits traders who want to understand robust statistics, regime filtering, and disciplined counter-trend risk management. It is a counter-stretch strategy: it fades price extremes back toward fair value, but only when a trend filter confirms the market is genuinely flat.
How It Works
The strategy recalculates its statistics once per closed bar and manages open trades on every tick. Here is the logic in plain English:
- Fair value (the centre): Over the last
Lookbackclosing prices, the strategy sorts the values, trimsTrimPercentfrom each tail, and averages the surviving central core. This trimmed mean (tm) is the anchor. - Band width (the spread): It measures the standard deviation of that same trimmed core (
td) and builds two bands — a lower band attm − EntryZ × tdand an upper band attm + EntryZ × td.EntryZcontrols how many trimmed standard deviations away a "stretch" must be. - Regime gate (the robustness filter): Before any trade, the strategy checks that the trimmed centre is roughly flat. It compares the current trimmed mean to the trimmed mean
SlopeLookbackbars ago; if that move exceedsFlatSlopeAtr × ATR, the market is deemed to be trending and the strategy stands aside. This is designed to avoid fading a runaway move — the classic mean-reversion blow-up. - Long entry — the strategy signals a long when the just-closed bar dips its low below the lower band (a statistical stretch) but then reclaims it, closing back above the lower band and closing bullish (close greater than open). The reclaim is read as the extreme being rejected.
- Short entry — the strategy signals a short as the mirror image: the bar pokes its high above the upper band, closes back below it, and closes bearish.
Exit and risk logic:
- Stop-loss: Placed just beyond the rejection bar's extreme (its low for longs, its high for shorts), padded by
StopBufferAtr × ATR. This is a tight, structural invalidation — if the reclaim proves false, the trade is closed quickly for a small loss. - Take-profit: Set at the trimmed mean itself — the fair-value target that reversion naturally aims for. The trade is only taken if the reward-to-risk ratio meets the
MinTargetRminimum. - Break-even lock: Once price travels halfway to the target, the stop is pulled up to the entry price, so a winning trade is protected from turning back into a loss.
- One position per symbol and magic number, with entries evaluated only once per closed bar.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| Lookback | 40 | 15 | 120 | Number of closing prices in the window used to compute the trimmed mean and its spread. |
| TrimPercent | 0.15 | 0.05 | 0.35 | Fraction of observations trimmed from each tail before averaging the central core. |
| EntryZ | 2.0 | 1.0 | 3.5 | Band half-width in trimmed standard deviations; controls how far a stretch must reach to signal. |
| SlopeLookback | 5 | 2 | 20 | Lag (in bars) used by the flat-centre regime gate to measure trend. |
| FlatSlopeAtr | 1.0 | 0.2 | 4.0 | Maximum allowed centre-line slope (in ATR units) for the market to count as "ranging." |
| AtrPeriod | 14 | 5 | 40 | Averaging period for the Average True Range (ATR) volatility measure. |
| StopBufferAtr | 0.6 | 0.1 | 2.0 | Extra padding (in ATR) placed beyond the rejection bar's extreme for the stop-loss. |
| MinTargetR | 0.8 | 0.3 | 3.0 | Minimum reward-to-risk ratio required before a trade is accepted. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade size in lots. |

Recommended Chart Settings
The Trimmed Mean Reversion Band was built and tuned with EURUSD in mind, and it operates on whichever single timeframe you attach it to. Because it fades extremes back to fair value, it tends to be most at home on liquid FX majors or metals where ranging conditions occur regularly and spreads are tight. Mid-range intraday timeframes (for example H1) are a reasonable starting point for study, but there is no universally "correct" chart. Market behaviour differs across instruments, sessions, and volatility regimes, so results will vary considerably from one setting to another. Always test any combination on historical data and a demo account before drawing conclusions.
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 core idea — using a trimmed mean instead of a plain average — is a genuine and well-established robust-statistics technique. By discarding the fat tails from both the centre and the spread, the strategy resists the distortion that spike bars cause in conventional bands. The flat-slope regime gate is a thoughtful addition: mean-reversion systems are most dangerous in strong trends, and refusing to fade a trending market is exactly the kind of discipline that helps keep drawdowns contained. The tight structural stop, fair-value target, and break-even lock all reinforce that low-drawdown intent.
Known limitations. No filter is perfect. The regime gate reduces trend exposure but cannot eliminate it — a market can transition from flat to trending within a single bar, catching a freshly opened fade on the wrong side. Trimmed statistics also require a reasonable sample; on very short lookbacks or thinly traded instruments the estimate becomes noisy. Because the target is the trimmed mean and stops are tight, the strategy can experience clusters of small losses during choppy, indecisive conditions where reclaims repeatedly fail. Mean-reversion approaches historically underperform in strongly trending or news-driven environments, and this one is no exception despite its guardrails.
Where it may underperform. Expect weaker behaviour during major economic releases, session opens with gapping, sustained directional moves, and low-liquidity periods where spreads widen. The strategy is an analytical framework for studying robust reversion — not a set-and-forget solution. Treat every parameter as a hypothesis to be tested rather than a guarantee.
Risk Management Tips
Sound risk management matters far more than any single entry rule. Consider these general principles as you study this EA:
- Position sizing: Size trades so that a losing streak cannot meaningfully damage your account. Many educators suggest risking no more than 1–2% of account equity per trade.
- Use a demo account first: Run the strategy on a demo or historical backtest for an extended period before ever considering live capital. This helps you understand its behaviour across different regimes.
- Understand drawdown: Even a strategy designed for low drawdown will have losing periods. Know the maximum historical drawdown you are prepared to tolerate, and stop trading if it is exceeded.
- Respect leverage: Leverage magnifies both gains and losses. Use it conservatively, especially while you are still learning how the strategy responds.
- Keep records: Journal your settings and observations so you can evaluate the strategy objectively rather than emotionally.
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: TrimmedMeanReversionBand.ex5 (12 downloads)
- Source Code: TrimmedMeanReversionBand.mq5 (15 downloads)
- Documentation: TrimmedMeanReversionBand.pdf (16 downloads)