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 Percent Range Trend Pullback strategy is a trend-following pullback system built around the Williams Percent Range (%R) oscillator, a momentum indicator that measures where the current price sits inside its recent high-to-low trading range. Rather than trying to predict tops and bottoms, this approach waits for an established trend and then looks to enter on temporary dips (in an uptrend) or temporary rallies (in a downtrend). It is a classic "buy strength on weakness" style of trading, packaged as an Expert Advisor (EA) for MetaTrader 5.
Direction is defined by a slope-filtered Exponential Moving Average (EMA) — a moving average that weights recent prices more heavily and reacts faster than a simple average. The strategy only considers long trades when the EMA is both above price and actually rising, and short trades only when the EMA is below price and actually falling. Timing is then handed to the Williams %R oscillator, which identifies when a pullback appears to be ending and the trend may be resuming. Both the trend filter and the %R trigger must agree on the same closed bar before any order is placed.
This EA is best understood as a learning tool for traders who want to study how a disciplined, rules-based pullback system is constructed. It demonstrates how a direction filter, a timing oscillator, and ATR-based (Average True Range) risk management can be combined into a single, self-scaling framework. It is designed for trending markets and is not a counter-trend or scalping system. As with any strategy, its behaviour will vary considerably across different symbols, timeframes, and market conditions.
How It Works
The strategy evaluates its rules once per closed bar — it does not react to every tick, which helps avoid noise from unfinished candles. On each newly-closed bar it checks the trend, the oscillator, and the risk levels before acting.
Trend filter (both conditions required):
- Uptrend: the signal bar's close is above the EMA, and the EMA today is higher than it was
EmaSlopeLookbackbars ago (the EMA is genuinely rising). - Downtrend: the signal bar's close is below the EMA, and the EMA today is lower than it was
EmaSlopeLookbackbars ago (the EMA is genuinely falling). - Requiring the EMA to actually be sloping — not merely having price on one side of it — is the main false-signal filter. It screens out flat, choppy ranges where pullback entries tend to get whipsawed.
Entry trigger (a %R crossover with a candle confirmation):
- The oversold line is calculated as
-(100 − PullbackDepth)and the overbought line as−PullbackDepth. With the default depth of 20, that places the oversold line at −80 and the overbought line at −20. - Long signal: the previous bar's %R was below the oversold line, the current %R has crossed back up to or above it, and the signal bar closed up (close above open). This may indicate that a dip has run its course and buyers are resuming control.
- Short signal: the previous bar's %R was above the overbought line, the current %R has crossed back down to or below it, and the signal bar closed down (close below open). This may indicate that a rally is fading and sellers are re-engaging.
- Demanding a real cross of the line plus a closing candle in the trade's direction helps avoid firing on a single deep wick that immediately reverses.
Stop-loss logic:
- When a trade is opened, the initial stop is placed
StopAtrMult × ATRbeyond the entry price — below entry for longs, above entry for shorts. Because the stop is sized from ATR (a measure of recent volatility), it self-scales to whatever symbol or timeframe you attach it to.
Take-profit logic:
- The take-profit is set at a fixed reward-to-risk multiple: the target distance equals
RewardRatio × (the stop distance). With the default 1.8, the strategy signals a target that is 1.8 times the initial risk.
Trade management:
- Once a position moves into profit, an ATR trailing stop of
TrailAtrMult × ATRfollows price. This trailing stop only ever ratchets in the trade's favour and never loosens — it locks in gains as a trend runs while still leaving room for the target to be reached. - Only one position per Magic number is allowed at a time, and a spread gate blocks new entries when the current spread is wider than
MaxSpreadPoints, avoiding entries when execution costs are unusually high.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| TrendEmaPeriod | 50 | 20 | 200 | Length of the trend EMA — the backbone that defines direction. |
| EmaSlopeLookback | 3 | 1 | 10 | How many bars back the EMA slope is measured over; the EMA must be rising/falling to trade. |
| WprPeriod | 14 | 7 | 40 | Lookback period for the Williams %R oscillator. |
| PullbackDepth | 20.0 | 10.0 | 35.0 | Pullback depth: oversold line = −(100 − depth), overbought line = −depth. |
| AtrPeriod | 14 | 7 | 28 | ATR period used for stop, target, and trail sizing. |
| StopAtrMult | 1.5 | 0.5 | 4.0 | Initial stop distance as a multiple of ATR beyond entry. |
| RewardRatio | 1.8 | 0.8 | 4.0 | Take-profit distance as a multiple of the stop distance (reward : risk). |
| TrailAtrMult | 2.0 | 0.5 | 5.0 | ATR trailing-stop distance once the trade is in profit (ratchets only in your favour). |
| MaxSpreadPoints | 30 | 1 | 200 | Skip entries when the current spread (in points) is wider than this. |
| Lots | 0.10 | 0.01 | 1.00 | Order volume (position size in lots). |
| Magic | 4821 | 0 | 9,999,999 | Unique identifier so the EA only manages its own trades. |

Recommended Chart Settings
This strategy was designed with trending instruments in mind — a trending major currency pair such as EURUSD or GBPUSD, or an index — on the M15 to H1 timeframes. That combination suits its trend-following, swing-style character: it aims to sit through pullback-and-resume cycles rather than scalp small intrabar moves.
Because the stop, target, and trailing distances are all derived from ATR, the framework adapts its risk sizing to the volatility of whatever symbol and timeframe you choose. That said, no single set of defaults is optimal everywhere. Trending pairs behave very differently from range-bound ones, and the same parameters can perform very differently across market conditions. Treat the recommended settings as a starting point for study and testing, not a fixed prescription, and always validate on historical data and a demo account before considering anything else.
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 has trade-offs, and understanding them is part of using any tool responsibly.
Strengths of this approach:
- The dual requirement — a sloping EMA and a %R crossover with a confirming candle — filters out many low-quality signals and keeps trades aligned with the prevailing trend.
- ATR-based stops, targets, and trailing make the system self-scaling, so it behaves sensibly across instruments with very different volatility profiles.
- A fixed reward-to-risk target combined with an ATR trailing stop is designed so that occasional sustained trends can produce larger winners, while losers are capped by the initial stop.
Known limitations:
- Williams %R, like all oscillators, can stay pinned in oversold or overbought territory during strong moves, producing missed entries or late re-entries.
- Pullback systems inherently struggle in choppy, sideways markets. The slope filter reduces this, but no filter eliminates whipsaws entirely, and a series of small losses can accumulate during range-bound periods.
- Requiring a same-bar directional close means some genuine reversals will be missed because the confirming candle did not form in time.
- Only one position is held per Magic number, so the EA will not pyramid or scale into a trend; this is a deliberate simplicity choice, not necessarily an optimal one.
The strategy tends to perform best when markets are trending cleanly and worst during extended consolidation. It is not a "set and forget" solution, and it should be studied, tested, and monitored rather than trusted blindly.
Risk Management Tips
Sound risk management matters far more than any single entry rule. Consider these general principles as you study this or any strategy:
- Position sizing: size each trade so that a full stop-loss represents only a small, predefined fraction of your account. A widely cited guideline is to risk no more than 1–2% of your account balance per trade.
- Understand drawdown: even a well-designed strategy will string together losing trades. Know the maximum historical drawdown you are willing to tolerate before you begin, and size accordingly.
- Test on a demo account first: run the EA on a demo or simulated account for an extended period so you understand its behaviour, frequency of trades, and how it handles different conditions before risking real capital.
- Verify spreads and costs: commissions, swaps, and spread all erode results. The built-in spread gate helps, but confirm your broker's typical conditions on your chosen instrument.
- Never over-leverage: leverage magnifies losses as much as gains. Keep effective leverage conservative, especially while learning.
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: PercentRangeTrendPullback.ex5 (3 downloads)
- Source Code: PercentRangeTrendPullback.mq5 (4 downloads)
- Documentation: PercentRangeTrendPullback.pdf (3 downloads)