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 Cumulative Sum Drift Shift strategy is a statistical change-point trend system for MetaTrader 5 built around the CUSUM (Cumulative Sum) control chart, a tool borrowed from industrial quality-control theory and adapted here into a trend-detection algorithm. Rather than reacting to the price level at a single instant — the way a moving-average crossover or a momentum threshold does — this approach accumulates statistical evidence over many bars before it commits to a trade. In simple terms, it waits until a series of small, same-direction price moves adds up to something that is unlikely to be random noise, and only then does it signal a potential regime shift.
The core idea is intuitive once you strip away the jargon. Each completed bar produces a close-to-close return. That return is standardized into "sigma units" (how many standard deviations it sits from its recent average) so the detector automatically adapts to the volatility of whatever instrument and timeframe you run it on. A small allowance value is then subtracted from each observation to bleed off ordinary chop, and the remainder is added to a running sum. When markets are directionless, the sum stays pinned near zero. When a genuine directional drift begins, the excesses pile up and the sum climbs until it crosses a decision interval — at which point a statistically meaningful trend is considered confirmed.
As a learning tool, this strategy is best suited to traders who are curious about how ideas from statistics and signal processing translate into trading logic. It is designed for trending market conditions and is intentionally slow to react in sideways ranges. If you want to study how a system can be "deaf to chop yet quick to lock onto an emerging trend," the Cumulative Sum Drift Shift is a clean, well-commented example of that philosophy in action.
How It Works
The strategy processes one completed bar at a time on the chart's timeframe. Here is the logic in plain English:
- Building the evidence window: For each new bar, the strategy computes the close-to-close return and keeps a rolling window of the most recent returns (controlled by
VolPeriod). It calculates the mean and standard deviation of that window. - Standardizing the move: The newest return is converted into a z-score —
(return − mean) / standard deviation. This expresses the move in sigma units, making the detector volatility-adjusted so it behaves consistently across symbols and timeframes. - Updating the two cumulative sums: The strategy maintains two running accumulators:
Cplus = max(0, previous Cplus + z − Slack)watches for upward drift.Cminus = max(0, previous Cminus − z − Slack)watches for downward drift.- The
Slackallowance is subtracted each bar, so random noise never lets the sums grow — they stay near zero until a real directional bias appears. - The entry signal:
- When
Cplusrises above theThreshold, an upward regime shift is confirmed and the strategy signals a long entry. - When
Cminusrises above theThreshold, a downward regime shift is confirmed and the strategy signals a short entry. - The moment either sum crosses the threshold, both accumulators reset to zero — the standard CUSUM restart — so the next shift is measured from a clean slate.
- Position management: If a signal aligns with a position you already hold, it is ignored. If a fresh signal points the opposite way, the strategy closes the existing trade and reverses into the new direction.
- Stop-loss logic: On entry, the stop is placed a distance of
AtrStopMult × ATRaway from the fill price, where ATR (Average True Range) measures recent volatility. This means the stop widens in volatile conditions and tightens in calm ones. - Take-profit logic: The target is set at a multiple of the stop distance defined by
RewardRiskRatio. With the default 1.5, the take-profit sits 1.5 times as far from entry as the stop — a fixed reward-to-risk relationship on every trade.
Because upward and downward rules are symmetric, the strategy treats long and short opportunities identically, and it runs entirely on the single timeframe you attach it to.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| VolPeriod | 20 | 10 | 60 | Rolling window (in bars) used to standardize returns into sigma units. Larger values smooth the volatility estimate. |
| Slack | 0.50 | 0.10 | 1.50 | The CUSUM allowance K in sigma units. Larger values ignore more noise before the sum begins to accumulate. |
| Threshold | 5.0 | 2.0 | 10.0 | The decision interval H in sigma units. Larger values produce fewer but statistically stronger signals. |
| AtrPeriod | 14 | 5 | 40 | Number of bars used to compute the ATR for stop and target sizing. |
| AtrStopMult | 2.0 | 0.5 | 5.0 | Stop distance expressed as this many ATRs from the entry price. |
| RewardRiskRatio | 1.5 | 0.5 | 5.0 | Take-profit distance as a reward-to-risk multiple of the stop distance. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade volume in lots. |

Recommended Chart Settings
The Cumulative Sum Drift Shift is designed to be instrument- and timeframe-agnostic because its z-score standardization adapts to whatever volatility it encounters. That said, statistical change-point detection tends to be most informative on liquid instruments with clean, continuous price action — major forex pairs such as EUR/USD or GBP/USD are a reasonable starting point for study.
For timeframe, intermediate charts such as H1 (1-hour) or H4 (4-hour) give the CUSUM enough bars to accumulate meaningful evidence without reacting to every tick of intraday noise. Lower timeframes generate more signals but also more false starts, while higher timeframes react more slowly. Keep in mind that results will vary considerably across different market conditions, sessions, and instruments — no single setting is optimal everywhere, which is exactly why the parameters above are exposed for experimentation on a demo account.
How to Install on MetaTrader 5
- Download the
CumulativeSumDriftShift.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
Strengths of this approach. The CUSUM method has a genuine statistical pedigree: it was engineered specifically to detect the onset of a shift as early as possible while resisting false alarms from random fluctuation. Applied to markets, this gives the strategy a useful character — it stays quiet during choppy, rangebound periods and only engages once evidence of a directional drift has accumulated. The volatility standardization means you are not forced to re-tune it for every instrument, and the ATR-based exits scale sensibly with market conditions.
Known limitations. Like all trend-detection systems, the Cumulative Sum Drift Shift can struggle in markets that oscillate without committing to a direction. In a persistent range, the accumulators may occasionally cross the threshold on a temporary burst, produce a signal, and then see price revert — a classic false breakout. The reset-and-reverse behavior can also lead to being "whipsawed" back and forth during transitional periods. Additionally, the strategy uses a fixed lot size and a fixed reward-to-risk target, so it does not adapt position size to account equity or to the confidence level of a given signal.
Where it may underperform. Expect weaker behavior in low-volatility, sideways markets and during major scheduled news events that cause sudden gaps unrelated to any statistical drift. The Threshold and Slack parameters are the primary levers governing sensitivity: set them too low and the system trades noise; set them too high and it may enter trends late. Finding a balance is part of the study, and it should always be validated out-of-sample rather than curve-fit to a single historical period.
Risk Management Tips
Sound risk management matters far more than any single entry signal. Consider these general principles as you study this or any strategy:
- Position sizing: Keep your trade size small relative to your account. A widely cited guideline is to risk no more than 1–2% of account equity on any single trade, adjusting the lot size so that the distance to your stop-loss corresponds to that fraction.
- Use a demo account first: Test the strategy in a risk-free simulated environment until you understand how it behaves across different conditions before ever considering real capital.
- Understand drawdown: Every strategy experiences losing streaks. Study the maximum peak-to-trough decline in equity so you know what a normal rough patch looks like and are not surprised by it.
- Respect your stops: The ATR-based stop-loss exists to cap the damage of any one trade. Overriding it manually defeats the risk framework the system is built on.
- Diversify and stay disciplined: Avoid concentrating all your risk in one instrument or one idea, and never add funds you cannot afford to lose in pursuit of recovering a loss.
Risk management is not about eliminating losses — that is impossible — but about ensuring no single trade or losing streak can meaningfully harm your account.
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: CumulativeSumDriftShift.ex5 (29 downloads)
- Source Code: CumulativeSumDriftShift.mq5 (31 downloads)
- Documentation: CumulativeSumDriftShift.pdf (34 downloads)