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 Trend Purity Pullback strategy is a selective, trend-following pullback system for MetaTrader 5 built around an original core measure the author calls Trend Purity, combined with a baseline EMA (Exponential Moving Average) — a moving average that weights recent prices more heavily than older ones. Instead of asking only how far price travelled or how straight the path was, Trend Purity asks the question a risk-conscious trader actually cares about: while the market trended, how badly did it ever move against a position? This makes the strategy a study in trade quality rather than raw signal frequency.
Trend Purity is calculated over a window of recent closing prices. The strategy takes the net displacement of price across the window, then measures the worst counter-excursion along that path — the deepest drop below the running peak in an uptrend, or the highest rise above the running trough in a downtrend. This worst counter-move is a form of Maximum Adverse Excursion (MAE), the largest unrealised loss a trade would have experienced. Purity is then defined as |displacement| / (|displacement| + MAE), a scale-free number between 0 and 1. A value near 1.0 describes a clean trend that marched one direction with only shallow pullbacks; a value near 0 describes a choppy, whipsaw-prone move dressed up as a trend.
This approach is designed for traders who want to study how a trend-pullback system filters for clean, orderly trends and enters on shallow retracements rather than chasing breakouts. It is best suited as a learning tool for intermediate students exploring how a custom trend-quality metric, a moving-average pullback trigger, and structural risk management fit together. It is not a shortcut of any kind — it is a framework for understanding disciplined, selective trend entries.
How It Works
The strategy processes each completed bar on a single timeframe and evaluates a sequence of conditions. It is fully symmetric, meaning the same logic applies to both long (buy) and short (sell) setups in mirror image.
Regime filter (is this a clean trend?):
- The strategy measures net displacement over the
Lookbackwindow and requires it to be large enough — at leastMinAtrMovemultiples of the current ATR (Average True Range), a volatility gauge based on the typical bar range. - It computes Trend Purity for the window and requires it to be at least
PurityThreshold, confirming the trend was clean rather than a chop-fest. - The baseline EMA must be sloping in the same direction as the net move (rising for longs, falling for shorts).
- Only when all three align does the strategy mark an active up- or down-trend regime.
Pullback (wait for a discount):
- Within an active regime, the strategy waits for price to dip back and touch the baseline EMA — a shallow retrace toward the trend line, not a breakdown of it. This arms a "pulled back" latch.
Reclaim trigger (the entry bar):
- For a long, the completed bar must close back above the EMA, be an up-candle (close above open), and take out the previous bar's high.
- For a short, the bar must close below the EMA, be a down-candle, and take out the previous bar's low.
- The bar that satisfies these conditions signals the entry.
Stop-loss logic (structural and strict):
- The stop is placed just beyond the recent pullback extreme — the highest high (for shorts) or lowest low (for longs) across the last
MaxPullbackBarsbars — with a small buffer of0.15 × ATR. - If the resulting risk distance is wider than
StopAtrMult × ATR, the setup is rejected as too loose. This "quality over quantity" rule is central to keeping historical drawdown small.
Take-profit and trade management:
- The take-profit is set at
RewardRatiomultiples of the structural stop distance. - Once price advances
BreakevenAtr × ATRin favour, the stop ratchets to breakeven, so a winner is less likely to turn into a meaningful loss. - After that, the stop trails
TrailAtr × ATRbehind price. Trade management runs on every tick for prompt protection, while entry signals are only evaluated on newly closed bars. - Only one position per magic number is held at a time.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| Lookback | 20 | 8 | 60 | Window, in completed bars, over which Trend Purity is measured. |
| PurityThreshold | 0.60 | 0.45 | 0.85 | Minimum Trend Purity (0–1) required to call the trend "clean". |
| BasePeriod | 21 | 8 | 80 | Baseline EMA period — the trend line price must pull back to and reclaim. |
| MinAtrMove | 1.5 | 0.5 | 4.0 | Minimum net displacement over the window, in ATRs (filters out non-trends). |
| MaxPullbackBars | 5 | 2 | 15 | How many recent bars form the pullback structure used for the stop. |
| AtrPeriod | 14 | 5 | 40 | ATR period used for volatility measurement and risk sizing. |
| StopAtrMult | 1.4 | 0.5 | 3.0 | Maximum allowed structural risk as an ATR multiple; wider setups are skipped. |
| RewardRatio | 2.0 | 1.0 | 4.0 | Take-profit = RewardRatio × the structural stop distance. |
| BreakevenAtr | 1.0 | 0.3 | 3.0 | Move the stop to breakeven once price advances this many ATRs in favour. |
| TrailAtr | 1.5 | 0.5 | 4.0 | After breakeven, trail the stop this many ATRs behind price. |
| Lots | 0.10 | 0.01 | 1.0 | Order volume (position size) per trade. |

Recommended Chart Settings
The Trend Purity Pullback strategy was designed with clean intraday and swing trends in mind, such as those seen on major FX pairs and index CFDs — for example EURUSD, XAUUSD (gold), or US100 — on timeframes from M15 to H4. The system is single-timeframe by design: every calculation uses the chart's own timeframe, so it adapts to whichever period you attach it to rather than hardcoding one.
Because the strategy filters aggressively for trend cleanliness, it will naturally trade less often on noisy, range-bound instruments and more often when a market is producing orderly directional moves. Results will vary considerably across different symbols, brokers, spreads, and market conditions, so treat the recommended settings as a starting point for study and testing rather than a fixed prescription.
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
Every strategy involves trade-offs, and understanding them is part of becoming a more disciplined trader.
Strengths of this approach:
- The Trend Purity filter is an intuitive way to separate orderly trends from choppy ones, which may help you avoid the whipsaw entries that plague simple moving-average systems.
- Structural stops tied to real pullback extremes, plus the rejection of setups that are "too loose," keep the risk per trade tightly defined.
- Breakeven and trailing logic aim to protect open profit, reducing the chance that a favourable move reverses into a loss.
Known limitations:
- Selective systems trade infrequently. During long ranging or low-volatility phases, the strategy may generate very few signals, which can test a trader's patience.
- Pullback-and-reclaim entries can still fail if a clean trend abruptly reverses right after price touches the moving average.
- A tight structural stop means the strategy can be stopped out by ordinary noise before a valid trend resumes, and trailing stops can exit winners early during volatile retracements.
- Like all trend-pullback methods, it historically performs best in trending conditions and may underperform in sideways, mean-reverting markets. No parameter set removes this dependency on market character.
Study how the strategy behaves across different symbols and timeframes before drawing conclusions, and remember that a backtest reflects the past, not the future.
Risk Management Tips
Sound risk management matters more than any single entry signal. As you study this strategy, keep these general principles in mind:
- Position sizing: Size trades relative to your account, not to a fixed lot habit. Many educational sources suggest risking no more than 1–2% of account equity per trade so that a string of losses does not do lasting damage.
- Use a demo account first: Test the EA on a demo or on historical data before committing real capital, so you can observe how often it trades and how it handles drawdown.
- Understand drawdown: Even a well-designed system experiences losing streaks. Know the largest historical drawdown you are prepared to tolerate, and confirm your position size keeps that within comfortable limits.
- Account for costs: Spreads, commissions, and slippage all affect real results, especially on lower timeframes where trades are more frequent.
- Keep expectations grounded: No strategy wins every trade. Focus on consistent process and disciplined risk control rather than the outcome of any individual position.
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: TrendPurityPullback.ex5 (21 downloads)
- Source Code: TrendPurityPullback.mq5 (23 downloads)
- Documentation: TrendPurityPullback.pdf (27 downloads)