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 Momentum Diffusion Trend Shift strategy is a trend-following Expert Advisor (EA) for MetaTrader 5 built around a diffusion index — an idea borrowed from market-breadth analysis and applied to a single price series. In classic breadth analysis, a diffusion index measures what fraction of many market members (stocks in an index, for example) are advancing at once. This strategy reuses that same "how broad is participation?" question, but the "members" are the last N completed bars on one chart rather than many separate instruments.
For each recent bar, the strategy asks a single yes/no question: is that bar's short-term momentum positive? Momentum here is simply the current close minus the close a few bars earlier. By counting up-votes against down-votes across a whole lookback window and normalizing the result, the strategy produces a signed diffusion index (DI) that ranges from -1 to +1. A reading near +1 means almost every recent bar is participating in an uptrend; a reading near -1 is the mirror image; and a reading near zero describes a balanced, choppy tape where up-momentum and down-momentum cancel each other out. This is deliberately different from a simple streak counter or the percentile of one momentum reading — it measures how widely spread the directional bias is across many overlapping momentum snapshots.
As a learning tool, this strategy is well suited to traders who want to understand breadth-style confirmation applied to a single market. Instead of reacting to the latest bar alone, it demands that a directional bias be distributed across a broad share of the recent window before it commits. It is best studied by intermediate traders who are already comfortable with moving averages, the Average True Range (ATR), and the mechanics of stop-loss and take-profit orders. Frame it as an analysis of how distributed momentum can be turned into signals — not as a shortcut to trading results.
How It Works
The strategy acts once per newly closed bar and works exclusively on a single timeframe. On each completed bar it rebuilds the diffusion index, smooths it, and checks for fresh threshold crossings. Here is the logic in plain English:
- Building the diffusion index: For each of the last
DiffusionWindowcompleted bars, the strategy computes momentum asClose[i] - Close[i - MomentumLookback]. Positive momentum counts as an up-vote, negative as a down-vote. The signed index is(upVotes - downVotes) / DiffusionWindow, giving a value between -1 and +1. - Smoothing: The raw index is passed through an Exponential Moving Average (EMA) of length
SmoothPeriodto reduce noise. SettingSmoothPeriodto 1 leaves the index untouched. - Regime filter: A baseline EMA of the closing price (
BaselineEma) defines the prevailing regime. Long signals are only allowed when price closes above this EMA; short signals only when price closes below it. This keeps entries aligned with the bigger-picture direction. - Long entry: The strategy signals a long when the smoothed diffusion index crosses up through
+SignalThreshold(participation has just turned broadly bullish) and the close is above the baseline EMA. - Short entry: The strategy signals a short when the smoothed index crosses down through
-SignalThresholdand the close is below the baseline EMA. - Fresh crossings only: Signals fire only on the bar where the index crosses the threshold, not on every bar it remains beyond it. This avoids re-entering the same move repeatedly.
- Breadth-flip exit: If a position is open and the index makes a fresh opposite crossing (for example, a down-cross while long), the strategy closes that position early. This "breadth flip" acts as an extra exit on top of the stop and target.
- Stop-loss logic: When a trade is opened, the stop distance is set to
AtrStopMult × ATR, where ATR is the Average True Range overAtrPeriodbars. This scales the stop to current volatility rather than using a fixed pip distance. - Take-profit logic: The take-profit is placed at
RewardRisk × stopDistancefrom entry, so the reward:risk ratio is defined directly by that parameter. - Spread filter: Before sending an order, the strategy skips the trade if the current spread exceeds
MaxSpreadPoints, helping avoid poor fills. Setting it to 0 disables the filter. - One position at a time: The EA manages a single open position per symbol and magic number, so it will not stack multiple trades in the same direction.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| DiffusionWindow | 20 | 8 | 60 | Number of recent bars whose momentum "votes" are polled for the diffusion index. |
| MomentumLookback | 3 | 1 | 15 | Momentum horizon: each vote is Close[i] - Close[i - MomentumLookback]. |
| SignalThreshold | 0.30 | 0.05 | 0.70 | Signed breadth level the smoothed index must cross to fire a signal (0–1 fraction). |
| SmoothPeriod | 3 | 1 | 15 | EMA smoothing period applied to the raw diffusion index (1 = no smoothing). |
| BaselineEma | 50 | 10 | 200 | Regime gate: longs only above this EMA of price, shorts only below it. |
| AtrPeriod | 14 | 5 | 40 | Number of bars used to calculate ATR for stop and target distances. |
| AtrStopMult | 2.0 | 0.5 | 5.0 | Stop distance expressed as this many ATRs from entry. |
| RewardRisk | 1.6 | 0.5 | 4.0 | Take-profit distance as a reward:risk multiple of the stop distance. |
| MaxSpreadPoints | 30 | 0 | 200 | Skip new trades when spread exceeds this value in points (0 = filter off). |
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade volume in lots. |

Recommended Chart Settings
This strategy was designed to run on a single timeframe, using the chart's own symbol and period for every calculation. A common starting point for study is a major forex pair such as EUR/USD on an intermediate intraday timeframe (for example, M15 to H1), where trends develop with enough bars to populate the diffusion window meaningfully. Because the default BaselineEma is 50 and the diffusion window needs several dozen bars of history, higher timeframes will produce fewer, slower signals, while lower timeframes will produce more frequent — and noisier — ones.
Remember that results will vary significantly across different instruments, timeframes, and market conditions. Always test the strategy on the specific symbol and timeframe you intend to study before drawing any conclusions, and re-check parameter behavior whenever you change markets.
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
The main strength of the Momentum Diffusion Trend Shift approach is that it requires distributed follow-through before acting. By demanding that momentum be positive across a broad share of the recent window — rather than only on the most recent bar — it filters out one-bar head-fakes and single-candle spikes. The baseline-EMA regime gate adds a second layer of alignment, and the symmetric threshold means long and short behavior are treated identically, which is useful for balanced study.
That said, this indicator has well-known limitations. Like all breadth and momentum tools, a diffusion index is inherently lagging: by the time a broad share of bars agrees on direction, part of the move may already be complete. In sharply ranging or whipsawing markets, the smoothed index can oscillate around the threshold, producing repeated crossings that lead to a series of small losing trades — a common failure mode for trend-following logic. The regime filter helps, but a flat or slowly drifting EMA offers weak protection when price chops directly across it.
The strategy may also underperform during sudden news-driven reversals, where a strong prior trend flips faster than the diffusion window can adapt. Because entries wait for a fresh threshold crossing, the EA can miss the earliest and often most efficient part of a new move. Treat this EA as a framework for understanding distributed-momentum signals and regime filtering, not as a finished system. Study its behavior across varied conditions, and consider how the window length, smoothing, and threshold interact before changing them.
Risk Management Tips
Sound risk management matters more than any single parameter setting. As you study this strategy, keep these general principles in mind:
- Risk a small, fixed fraction per trade. Many educators suggest never risking more than 1–2% of account equity on any single position. Size your lots so that the ATR-based stop distance corresponds to that fraction, rather than trading a fixed lot size blindly.
- Understand drawdown. Even a well-constructed trend strategy can experience long sequences of losing trades during choppy markets. Know how much peak-to-trough decline you are prepared to tolerate before you begin.
- Always start on a demo account. Run the EA on a demo or simulated environment first to observe how it behaves in real time, how often it trades, and how it handles spread and volatility on your chosen symbol.
- Account for spread and slippage. The
MaxSpreadPointsfilter helps, but real fills can still differ from expectations, especially around news events. Factor these costs into your analysis. - Never trade with money you cannot afford to lose, and avoid over-leveraging. Leverage magnifies both gains and losses, and the losses are what end accounts.
Used thoughtfully, this EA is a useful way to explore how breadth-style momentum aggregation, volatility-scaled stops, and regime filtering combine into a single rules-based approach.
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: MomentumDiffusionTrendShift.ex5 (30 downloads)
- Source Code: MomentumDiffusionTrendShift.mq5 (29 downloads)
- Documentation: MomentumDiffusionTrendShift.pdf (40 downloads)