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?
Directional Coherence Emergence is an MetaTrader 5 expert advisor built around a single original concept: the directional coherence order parameter, a statistical measure of how "ordered" a sequence of price moves has become. Rather than leaning on a conventional indicator such as a moving average, oscillator, or price band, this strategy treats each closed bar as a coin flip — up or down — and measures whether recent bars have organized themselves into a coherent directional run or scattered into random noise. Its trading style is best described as adaptive momentum-emergence: it looks for the moment a directional regime is born and rides it until that order dissolves.
The core idea comes from statistical physics. In a truly random, memoryless market, the sign of each bar's return should flip about half the time. By counting how often the sign actually alternates over a rolling window and comparing that against the random baseline, the strategy computes a dimensionless coherence value C that ranges from +1 (a strong, uninterrupted directional run) through 0 (no structure at all) to −1 (choppy, alternating, mean-reverting price action). This is a pure combinatorial measure of run structure — not an autocorrelation, chart pattern, or classic technical indicator.
As a learning tool, Directional Coherence Emergence is well suited to traders who want to explore regime-detection concepts and self-calibrating systems rather than fixed indicator thresholds. It is designed for trending or momentum-driven conditions, where directional order genuinely emerges and persists. Beginners can study it as a clean example of turning a first-principles hypothesis into code, while more experienced traders may find value in its adaptive, parameter-light approach to defining what "unusually ordered" means for any given market.
How It Works
The strategy processes data once per closed bar and reduces each bar to the sign of its return. Over a rolling window of these signs it counts the alternations (sign flips) and converts that count into the coherence value C using the formula C = 1 − 2A/(N−1), where A is the number of alternations and N is the window length.
Crucially, the entry threshold is not a hand-picked number. The strategy measures the mean and standard deviation of its own recent coherence readings and floats a self-calibrated barrier at theta = mean(C) + K × std(C). This lets it continuously recalibrate to whatever "unusually ordered" looks like for the current symbol and timeframe.
Entry conditions — the strategy signals a trade when:
- Enough closed bars have accumulated to fill the coherence window plus its adaptive lookback.
- Coherence emerges through the barrier — that is, the previous bar's coherence was at or below
thetaand the current bar's coherence rises strictly above it. This "crossing up" is treated as the birth of a directional regime. - The net displacement of the window is non-zero, which reveals the direction of the newly formed order.
- When these align, the strategy signals a buy if the window's net displacement is positive (order points up) or a sell if it is negative (order points down).
Exit conditions:
- The strategy exits an open position the moment coherence decays back below zero. A run that stops being coherent is treated as having spent its directional energy, so the position is closed to bank out before the structure fully dissolves into randomness or anti-persistence.
- Positions also close naturally when either the stop-loss or take-profit level is reached.
Stop-loss logic:
- The stop distance is a fixed volatility budget:
ATR × StopAtrMult. ATR (Average True Range) measures recent price volatility, so the stop automatically widens in fast markets and tightens in calm ones.
Take-profit logic:
- The profit target stretches with the strength of order at entry:
TP = ATR × TpAtrMult × (1 + max(0, C_entry)). - In plain terms, when a strongly ordered run is detected, the target is pushed further away to give the move room to run; when the emerging order is weak, the target stays closer and the trade behaves more like a scalp.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| CoherenceWindow | 20 | 8 | 60 | Number of bar-return signs used to measure run coherence. Larger windows smooth the signal and demand longer runs. |
| AdaptLookback | 60 | 20 | 150 | Trailing window over which the coherence signal's own mean and standard deviation are measured to set the adaptive barrier. |
| ThresholdK | 0.6 | -0.5 | 2.5 | Multiplier in the barrier mean(C) + K × std(C). Higher K makes emergences rarer and, in principle, stronger. |
| AtrPeriod | 14 | 5 | 30 | Number of bars used by the ATR volatility calculation that sizes the stop. |
| StopAtrMult | 1.6 | 0.5 | 4.0 | Stop-loss distance as a multiple of ATR (the raw volatility budget). |
| TpAtrMult | 2.4 | 1.0 | 6.0 | Base take-profit multiple of ATR, before it is stretched by the coherence strength at entry. |
| Lots | 0.10 | 0.01 | 1.0 | Trade volume in lots. |

Recommended Chart Settings
Directional Coherence Emergence is symbol- and timeframe-agnostic by design, because its adaptive barrier recalibrates to each market's own coherence distribution. That said, it is most instructive to study on a liquid instrument such as a major forex pair (for example EUR/USD) on an intraday timeframe like M15 or H1, where enough bars form to keep the adaptive lookback populated and where directional regimes appear frequently enough to observe.
Because the entry threshold self-calibrates, the strategy does not require you to hunt for "magic" levels per market. However, results will vary considerably across different symbols, timeframes, and market conditions. Always test on the specific instrument and timeframe you intend to study before drawing any conclusions, and remember that a regime-detection approach behaves very differently in trending versus ranging environments.
How to Install on MetaTrader 5
- Download the
.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 the approach. The most distinctive feature of Directional Coherence Emergence is that it defines its own entry threshold. Instead of a fixed, hand-tuned level that may fit one market and fail on another, the barrier floats with the coherence signal's own statistics. This self-adaptation is elegant and reduces the temptation to over-optimize. The coherence measure itself is transparent and grounded in a clear random-walk null hypothesis, which makes the strategy a genuinely useful teaching example of turning a first-principles idea into working code. The volatility-scaled stop and coherence-stretched target are also thoughtful attempts to match risk and reward to prevailing conditions.
Known limitations. Reducing each bar to a sign discards magnitude information — a tiny move and a large move count the same, so coherence can look high even when the underlying price change is economically small. The strategy assumes that once directional order emerges it will persist long enough to be tradable, but many "emergences" can be short-lived, especially on noisy lower timeframes where a single bar can flip the sign sequence. The exit rule (close when C drops below zero) reacts to structure decay rather than to price, so it may hold through adverse moves that have not yet altered the sign pattern, or exit trades that were merely pausing.
Where it may underperform. In tightly ranging, low-volatility, or headline-driven markets, coherence can whipsaw around the barrier and generate frequent signals that reverse quickly. Spread and commission costs also weigh more heavily on the shorter, weakly ordered trades that the strategy scalps. As with any regime detector, it tends to shine in persistent trends and struggle in directionless chop — the very conditions its coherence value is designed to flag as C near or below zero.
Risk Management Tips
Sound risk management matters far more than any single entry signal. Consider the following general principles as you study this EA:
- Position sizing: Size trades so that a losing streak cannot materially damage your account. Many educational sources suggest risking no more than 1–2% of account equity per trade.
- Respect drawdown: Every strategy experiences losing periods. Understand the potential drawdown before committing capital, and decide in advance how much you are willing to lose.
- Use a demo account first: Test the EA thoroughly on a demo or simulated account to understand its behavior across different market conditions before considering any live use.
- Diversify and avoid over-leverage: Concentrated, highly leveraged positions amplify both gains and losses. Leverage should be treated with caution.
- Keep expectations realistic: No parameter set performs well in all environments. Ongoing observation, journaling, and review are part of responsible strategy study.
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: DirectionalCoherenceEmergence.ex5 (0 downloads)
- Source Code: DirectionalCoherenceEmergence.mq5 (0 downloads)
- Documentation: DirectionalCoherenceEmergence.pdf (0 downloads)