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?
Empirical Mode Regime Shift is a trend-following expert advisor built around John Ehlers' Empirical Mode Decomposition (EMD), a signal-processing technique that separates a price series into a repeating cycle component and a slower trend component. Rather than reacting to raw candles, the strategy first runs price through an Ehlers two-pole band-pass filter — a mathematical filter that isolates the market's dominant swing rhythm while rejecting both very slow drift and short-term tick noise. From that clean cycle signal it estimates whether the market is genuinely trending or simply oscillating around a fair value.
The core idea is regime classification. Markets alternate between trending phases, where price moves persistently in one direction, and consolidation phases, where price chops sideways. Fixed-threshold trend systems tend to fire false signals during chop. Empirical Mode Regime Shift addresses this by building adaptive threshold bands from the market's own recent swing amplitude, so the trend estimate must clear a volatility-scaled hurdle before the strategy commits to a directional trade. This makes it a study in regime detection rather than a simple moving-average crossover.
As a learning tool, this EA suits traders who want to understand how cycle analysis, adaptive filtering, and volatility-based risk sizing fit together in a single, mechanical framework. It is designed for trending markets and deliberately sits on its hands during consolidation. It is best explored on a demo account by intermediate traders curious about Ehlers-style digital signal processing applied to price.
How It Works
The strategy processes one completed bar at a time and only acts when the detected market regime flips. Here is the logic in plain English:
- Build the cycle signal. For each completed bar, the strategy takes the median price
(High + Low) / 2and feeds it into the Ehlers two-pole band-pass filter, tuned to theCyclePeriodlength and shaped by theBandwidthsetting. The output, called the band-pass (BP) value, is an oscillation that swings above and below zero as the market cycles. - Estimate the trend-of-cycle. The strategy averages the band-pass value over the last
CyclePeriodbars. When the market merely oscillates, this mean hugs zero. When a real trend develops, the cycle spends more time on one side of zero and the mean drifts away from it. - Build adaptive bands. Instead of using fixed levels, the strategy scans the last
PeakWindowbars for the peaks and valleys of the band-pass signal, averages them, and multiplies byThresholdFraction. This produces an upper band (positive) and a lower band (negative) that automatically expand and contract with market volatility. If no clear turning point exists yet, it falls back to the window's extreme value. - Classify the regime. If the trend-of-cycle rises above the positive upper band, the regime is an uptrend. If it falls below the negative lower band, the regime is a downtrend. Anything in between is treated as consolidation, and no new trend trade is taken.
- Entry on a regime flip. The strategy signals a long only when the regime turns up after previously not being up, and a short only when the regime turns down after previously not being down. On an up-flip it closes any open short and opens a long; on a down-flip it closes any open long and opens a short. Long and short rules are exact mirror images.
- Consolidation holds. When the regime cools to consolidation, the strategy holds its current position rather than exiting — the reasoning is that the trend paused, it did not reverse.
- Stop-loss logic. Protective stops are volatility-scaled. The strategy measures the Average True Range (ATR) — a common measure of recent price volatility — over
AtrPeriodbars and places the stopAtrStopMult × ATRaway from the entry price. - Take-profit logic. The take-profit distance is set to
RewardRisk × stop distance, so aRewardRiskof 2.0 targets a reward twice the size of the risk on each trade.
Because risk distances travel with ATR, the stop and target automatically widen in volatile conditions and tighten in calm ones, without any manual re-tuning per symbol.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| CyclePeriod | 20 | 10 | 40 | Dominant cycle length the band-pass filter is tuned to; also the window for the trend-of-cycle mean. |
| Bandwidth | 0.30 | 0.10 | 0.60 | Band-pass fractional bandwidth. Smaller values isolate a narrower, tighter cycle. |
| PeakWindow | 50 | 20 | 100 | Number of bars over which band-pass peaks and valleys are averaged into the adaptive bands. |
| ThresholdFraction | 0.50 | 0.20 | 0.90 | Fraction of the average peak/valley used as the regime trigger band. Higher values demand a stronger trend before committing. |
| AtrPeriod | 14 | 7 | 30 | Number of bars used to calculate ATR for the protective stop. |
| AtrStopMult | 2.0 | 1.0 | 4.0 | Stop-loss distance as a multiple of ATR. |
| RewardRisk | 2.0 | 1.0 | 5.0 | Take-profit distance as a multiple of the stop distance (reward-to-risk ratio). |
| Lots | 0.10 | 0.01 | 1.0 | Order volume in lots per trade. |

Recommended Chart Settings
Empirical Mode Regime Shift is a single-timeframe strategy — every calculation uses the chart's own timeframe, so it runs on whatever period you attach it to. Because it depends on a clean, well-defined price cycle, it tends to be most coherent on liquid instruments with orderly swings, such as major forex pairs (for example EUR/USD or GBP/USD) on intermediate timeframes like H1 or H4, where cycles are long enough to filter cleanly but frequent enough to generate signals.
The default CyclePeriod of 20 assumes a dominant swing roughly 20 bars long; if you trade a market with a different natural rhythm, that value is the first thing to review. Keep in mind that behaviour will vary considerably across symbols, timeframes, and market conditions. Always validate any settings on historical data and a demo account before considering live use.
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. The adaptive band mechanism is the strategy's most interesting feature. By deriving thresholds from the market's own recent swing amplitude, it aims to filter out the whipsaws that plague fixed-threshold trend systems during choppy periods, while the near-zero-lag band-pass filter is designed to detect genuine regime changes relatively early. Volatility-scaled stops and targets add a layer of consistent, mechanical risk framing.
Known limitations. EMD and band-pass filters assume the market has a reasonably stable dominant cycle. In practice, that cycle drifts, and during sudden news-driven shocks the filter can lag or misread the signal. Because the strategy trades only on regime flips and holds through consolidation, it may sit through extended sideways stretches without acting — and when it does flip, it can enter after a portion of the move has already occurred. Reversing directly from long to short on a flip can also result in back-to-back losses if the market is ranging near a threshold.
Where it may underperform. Tight, low-volatility ranges where the trend-of-cycle repeatedly grazes the bands can produce false flips. Very fast, gapping markets can also outrun the ATR-based stop. As with any single-timeframe trend system, no fixed parameter set will suit every symbol or every market phase, so ongoing review is essential.
Risk Management Tips
Sound risk management matters far more than any single indicator. Consider these general principles as you study this strategy:
- Risk a small, fixed fraction per trade. Many educational sources suggest risking no more than 1–2% of account equity on any single position. Size your
Lotsso the ATR-based stop distance stays within that limit. - Test on a demo account first. Run the EA in a risk-free simulated environment until you understand how it behaves across trending and ranging conditions.
- Understand drawdown. Even a well-designed trend system endures losing streaks during consolidation. Know the maximum peak-to-trough decline you are willing to tolerate before committing capital.
- Diversify and avoid over-optimization. Curve-fitting parameters to past data rarely holds up going forward. Prefer robust settings that work reasonably across multiple periods over settings that look perfect on one.
- Keep leverage modest. Leverage amplifies both gains and losses; conservative sizing gives a strategy room to survive normal variance.
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: EmpiricalModeRegimeShift.ex5 (56 downloads)
- Source Code: EmpiricalModeRegimeShift.mq5 (63 downloads)
- Documentation: EmpiricalModeRegimeShift.pdf (62 downloads)