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 Deviation Reset Continuation strategy is a trend-continuation system built around a volatility-normalized deviation of price from an EMA (Exponential Moving Average) baseline. An EMA is a moving average that weights recent prices more heavily, giving you a smooth "fair value" line that the market tends to drift around. Rather than trying to catch tops and bottoms, this approach is designed for markets that are already trending and periodically pausing before pushing on in the same direction.
The core gauge behind the strategy is a measurement the code calls the "stretch": the distance between the current close and the EMA baseline, divided by the ATR (Average True Range — a common measure of how much price typically moves per bar). Expressed as stretch = (close − EMA) / ATR, this tells you how many ATRs price is trading away from its own baseline. Because the deviation is divided by ATR, it becomes scale-free, so the same thresholds behave consistently across different symbols, price levels, and timeframes. This is a deliberate guard against overfitting to one particular market.
As a learning tool, this strategy is well suited to traders who want to study how trend-following systems distinguish a healthy pullback from a genuine reversal. Healthy trends rarely move in a straight line — they extend, pull back toward the baseline, then resume. This system does not fade the extension; instead it waits for the stretch to "reset" toward zero and then looks to join the resumption, always in the direction the baseline is already sloping. It is best viewed as a structured example of trend-continuation logic rather than a shortcut of any kind.
How It Works
The strategy runs as a small, non-repainting state machine that only evaluates closed bars — it never acts on an unfinished candle, which avoids the false signals that come from mid-bar noise. The logic moves through three stages before a trade can open:
- Regime filter (the trend must exist first): The EMA baseline must be sloping. The strategy measures the slope over the last
SlopeLookbackbars. If the baseline is rising, only long setups are considered; if it is falling, only short setups. If there is no clear slope, no trades are taken at all — the system only ever trades with the prevailing direction. - Arm the setup (wait for the reset): While the trend regime holds, the strategy waits for the stretch to pull back toward the baseline. For a long, the stretch must fall to at or below
PullbackDepth; for a short, it must rise to at or above the negative ofPullbackDepth. This identifies a genuine dip (or rally) back toward fair value rather than chasing an already-extended move. - Resumption trigger (join the continuation): Once armed, the strategy signals an entry only when the trend re-extends. For a long, the signal bar must close higher than it opened, close above the prior bar's high, and the stretch must climb back to at least
ResumeLevel. For a short, the bar must close lower than it opened, close below the prior bar's low, and the stretch must fall to−ResumeLevelor lower. The long and short rules are fully symmetric.
If the regime flips direction, or MaxWaitBars pass without a resumption, the armed setup is abandoned and the strategy goes back to scanning. This time limit keeps the system from clinging to a stale idea.
For exits and risk, the strategy relies on three mechanisms working together:
- Stop-loss: Placed at a distance of
StopAtrMult × ATRfrom entry, so the stop automatically widens in volatile conditions and tightens in calm ones. - Take-profit: Set at a reward-to-risk multiple of the stop distance, defined by
RewardRiskRatio. With the default 2.0, the target sits twice as far from entry as the stop. - Trailing stop: A Chandelier-style ATR trail set at
TrailAtrMult × ATR. It only ever ratchets in the trade's favour, never loosening, which is intended to lock in open profit and reduce givebacks if a trend runs.
The strategy holds exactly one position per magic number — no averaging, no grid, no adding to losers. Position size uses fixed-fractional sizing that scales the base lot with account balance and clamps it to a hard ceiling.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| BasisPeriod | 34 | 10 | 100 | Period of the EMA baseline the deviation is measured from. |
| AtrPeriod | 14 | 7 | 30 | ATR period, used both to normalize the deviation and to size the risk unit. |
| SlopeLookback | 5 | 2 | 20 | Number of bars over which the baseline slope (the regime) is measured. |
| PullbackDepth | 0.30 | -0.50 | 1.50 | Arms the setup once the stretch pulls back to at or below this level (in ATRs). |
| ResumeLevel | 0.60 | 0.00 | 2.00 | Resumption trigger — the stretch must re-extend beyond this level (in ATRs). |
| MaxWaitBars | 6 | 2 | 20 | How many bars the strategy keeps waiting for a resumption after arming. |
| StopAtrMult | 2.0 | 1.0 | 4.0 | Initial stop distance as a multiple of ATR. |
| RewardRiskRatio | 2.0 | 1.0 | 5.0 | Take-profit as a reward-to-risk multiple of the stop distance. |
| TrailAtrMult | 2.5 | 1.0 | 5.0 | ATR trailing-stop multiple; ratchets only in the trade's favour. |
| BaseLots | 0.10 | 0.01 | 1.00 | Fixed-fractional base lot size. |
| MaxLots | 2.00 | 0.10 | 10.0 | Hard ceiling on position size. |
| Magic | 517033 | 0 | 9,999,999 | Magic number that tags and isolates this EA's trades. |

Recommended Chart Settings
The Deviation Reset Continuation strategy was designed with trending FX majors, metals, and indices in mind, on the M30 to H4 timeframes. These timeframes tend to produce cleaner, more persistent trends than very short intraday charts, which suits a continuation approach that waits for a pullback and a fresh push.
That said, nothing about the symbol or timeframe is hardcoded — the ATR normalization means the same thresholds are intended to travel reasonably well across instruments. Because market conditions vary widely, results will differ from one symbol, period, and volatility regime to another. Any timeframe or symbol you consider should be studied on a demo account first so you can see how the arming and resumption logic behaves in that specific context.
How to Install on MetaTrader 5
- Download the
DeviationResetContinuation.ex5file 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 conditions it is built for and conditions where it struggles. Understanding both is part of using any tool responsibly.
Strengths of this approach:
- The regime filter keeps trades aligned with the prevailing trend, which historically helps trend-continuation systems avoid fighting a strong move.
- The ATR-normalized "stretch" makes thresholds consistent across symbols and timeframes, reducing the temptation to over-tune for one market.
- Risk is defined before entry through an ATR stop and reward-to-risk target, and the Chandelier trail is designed to protect open profit as a trend develops.
- The one-position-per-magic rule avoids the compounding risk of averaging or grid systems.
Known limitations:
- Like all trend-continuation logic, this strategy can underperform in ranging or choppy markets, where the baseline has no clear slope and pullbacks fail to resume. In those conditions it may either sit idle or take setups that stall out at the stop.
- The
MaxWaitBarswindow means some valid continuations that arrive slowly may be abandoned before they trigger. - Whipsaws around the EMA — where slope flips back and forth — can invalidate armed setups repeatedly.
- Backtested behaviour reflects historical data only and may not represent how the strategy responds to future volatility, spreads, slippage, or news-driven gaps.
The goal here is education, not persuasion. Study why a signal fires and why some setups are abandoned; that understanding is far more valuable than any single result.
Risk Management Tips
Sound risk management matters more than any individual entry signal. A few widely taught principles:
- Risk a small, fixed fraction per trade. Many educators suggest risking no more than 1–2% of account equity on any single position, so that a string of losses does not threaten the account.
- Size positions deliberately. Understand how the
BaseLots,MaxLots, and ATR-based stop interact to determine your actual monetary risk per trade before you commit real capital. - Test on a demo account first. Run the strategy in a risk-free simulated environment until you understand its behaviour across different market conditions.
- Understand drawdown. Every strategy experiences losing streaks. Know the maximum drawdown you are prepared to tolerate, and treat that limit as a hard boundary.
- Account for real-world costs. Spreads, commissions, slippage, and swap fees all affect outcomes and are easy to overlook in idealized testing.
Risk management is not a feature you switch on once — it is a discipline you apply on every single trade.
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: DeviationResetContinuation.ex5 (0 downloads)
- Source Code: DeviationResetContinuation.mq5 (0 downloads)
- Documentation: DeviationResetContinuation.pdf (0 downloads)