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 Trend Detection Index Emergence strategy is a trend-following expert advisor (EA) built around the Trend Detection Index (TDI), a classic but under-used momentum indicator developed by M. H. Pee. Unlike a moving-average crossover or a simple momentum line, the TDI is designed to answer a single, disciplined question: is the market's recent directional push actually bigger than its own recent background noise? In other words, it tries to separate a genuine trend that is emerging from the endless small oscillations that occur inside a sideways, choppy market.
The strategy works entirely from closing prices. It measures how far price has traveled in one net direction over a recent window (a value called the Direction Indicator, or DI) and compares that to the accumulated absolute movement over an older, equal-length window (a proxy for background "noise"). When the recent net displacement outgrows that older noise band, the TDI reads positive and a trend is considered present. The direction of the DI then tells you whether it is an up-trend or a down-trend. This makes the Trend Detection Index Emergence approach a swing-style, trend-following system rather than a scalping or mean-reversion tool.
As a learning tool, this EA is well suited to traders who want to study how momentum can be filtered against market noise instead of taken at face value. It is most relevant to liquid, trending instruments — think EURUSD, GBPUSD, or XAUUSD (gold) on the H1 (1-hour) timeframe. If you are exploring how to avoid the mid-range whipsaws that punish naïve momentum crossovers, the Trend Detection Index Emergence strategy offers a clear, well-documented example to examine.
How It Works
The strategy evaluates the Trend Detection Index once per newly closed bar and only acts on confirmed, closed-bar data. Here is the logic in plain English:
- Building the indicator: For each bar, the strategy calculates momentum as the difference between the current close and the close a set number of bars ago. It sums these momentum values over the recent window to get the DI (net direction), and sums the absolute momentum values over the older window to get the noise band (called
absTail). The final TDI = |DI| − noise band. - Trend confirmation: A trend is only recognized when the TDI is positive by the required margin. When
TrendMarginis left at zero, this is simply the textbook rule TDI > 0. A positive DI signals an up-trend; a negative DI signals a down-trend. - Long entry signal: The strategy signals a long when the TDI turns positive with DI > 0 for the first time — meaning the previous bar was not yet a confirmed up-trend. This captures the emergence (ignition) of a fresh up-trend rather than chasing one already in progress.
- Short entry signal: The strategy signals a short when the TDI turns positive with DI < 0 for the first time, catching a newly detected down-trend.
- Active exit: Because the same indicator can tell you when a trend dies, an open position is closed the moment the detector says the trend edge is gone — that is, the TDI falls back to non-trending, or the DI flips direction. The strategy does not wait for the stop when the very condition that justified the trade has evaporated.
- Stop-loss logic: Risk is volatility-scaled using the Average True Range (ATR), an indicator that measures a market's typical bar-to-bar range. The protective stop is placed at
AtrStopMult × ATRaway from entry, so it automatically widens in volatile conditions and tightens in calm ones. - Take-profit logic: The target is set at
AtrTargetMult × ATRfrom entry. With the default settings, the target distance is larger than the stop distance, aiming for a positive reward-to-risk (R) multiple on winning trades. - Trade filters: Only one position per Magic number is held at a time, and a new entry is skipped if the current spread is wider than the
MaxSpreadPointslimit — helping avoid entries during poor-liquidity conditions.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| Period | 20 | 8 | 40 | Momentum lookback for the TDI. The background-noise window spans twice this length. |
| AtrPeriod | 14 | 7 | 30 | Number of bars used to calculate ATR for the stop and target. |
| AtrStopMult | 2.50 | 1.00 | 5.00 | Protective stop distance as a multiple of ATR. |
| AtrTargetMult | 4.00 | 1.00 | 8.00 | Take-profit distance as a multiple of ATR. |
| TrendMargin | 0.00 | 0.00 | 0.50 | Decisiveness gate: requires TDI to clear zero by this fraction of the noise band. Zero equals the textbook TDI > 0 rule. |
| MaxSpreadPoints | 30 | 1 | 200 | Skips an entry if the current spread (in points) is wider than this. |
| Lots | 0.10 | 0.01 | 1.00 | Fixed order volume (lot size) for each trade. |
| Magic | 8137 | 0 | 9,999,999 | Unique identifier so the EA manages only its own positions. |

Recommended Chart Settings
The Trend Detection Index Emergence strategy was designed with a liquid, trending market and a swing horizon in mind. The default "playground" is a major or well-known trender such as EURUSD, GBPUSD, or XAUUSD (gold) on the H1 (1-hour) timeframe. On this timeframe the TDI's momentum-versus-noise comparison has enough data to be meaningful without becoming sluggish.
Keep in mind that no single symbol or timeframe is universally optimal. Trend-following logic tends to perform differently across ranging versus trending regimes, and results will vary considerably with market conditions, broker spreads, and the specific period you test. Treat the recommended settings as a starting point for your own study rather than a fixed prescription, and always validate any configuration on a demo account first.
How to Install on MetaTrader 5
- Download the
TrendDetectionIndexEmergence.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
The strength of the Trend Detection Index Emergence approach is its built-in noise filter. By demanding that summed directional momentum beat the market's own accumulated noise, the strategy is designed to sit out the mid-range whipsaws where simple momentum crossovers tend to bleed. Trading only the transition into a confirmed trend — the emergence — is a disciplined way to avoid chasing moves that are already mature. The active exit is another thoughtful feature: it releases a position as soon as the detector says the edge is gone, rather than passively waiting for a stop.
That said, this indicator has known limitations. Like all trend-detection tools, the TDI is inherently reactive — it confirms a trend only after enough displacement has accumulated, so entries can arrive somewhat late relative to the start of a move. In genuinely range-bound or rapidly reversing markets, the strategy may still generate false emergence signals that are quickly closed by the active exit, producing a series of small losses. The fixed lot size means position sizing does not automatically scale with account equity, and the ATR-based stop, while adaptive, cannot protect against gaps or slippage during high-impact news.
Performance will also depend heavily on the chosen Period and TrendMargin. A shorter period reacts faster but is noisier; a higher TrendMargin demands a more decisive break above the noise band, which may reduce false signals at the cost of fewer trades. This EA is best treated as an educational framework for studying trend emergence — not as a finished, hands-off system.
Risk Management Tips
Sound risk management matters far more than any single indicator. Consider these general principles as you study the strategy:
- Risk a small, fixed fraction per trade. Many educators suggest never risking more than 1–2% of your account on any single position. Adjust the
Lotsvalue so that the ATR-based stop distance corresponds to that fraction, rather than using an arbitrary lot size. - Understand drawdown. Even a well-designed trend system will endure losing streaks during choppy periods. Know in advance how much peak-to-trough decline you are willing to tolerate before you would pause or re-evaluate.
- Start on a demo account. Test the EA in a risk-free simulated environment until you understand its behavior across different market conditions and confirm it interacts correctly with your broker's spreads and execution.
- Mind the spread and session. The
MaxSpreadPointsfilter helps, but trading around major news releases or thin liquidity hours can still cause slippage. Consider which sessions suit your chosen symbol. - Diversify and size sensibly. Avoid concentrating all your risk in one instrument or one strategy, and keep overall exposure aligned with your personal risk tolerance and financial situation.
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: TrendDetectionIndexEmergence.ex5 (7 downloads)
- Source Code: TrendDetectionIndexEmergence.mq5 (6 downloads)
- Documentation: TrendDetectionIndexEmergence.pdf (13 downloads)