Blog / Strategy
Strategy

Directional Persistence Regime Switch

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 Directional Persistence Regime Switch is an adaptive Expert Advisor (EA) for MetaTrader 5 built around a single, unusual measurement: the lag-1 sign autocorrelation of close-to-close returns. Instead of relying on a moving average, RSI, or a chart pattern, it reduces the price tape to a stream of directional decisions — up, down, or flat — and asks one statistical question: does one push tend to be followed by another push, or by a reversal? That question is answered by a "regime coordinate" the strategy calls rho (ρ), a scale-free value between -1 and +1. An Average True Range (ATR) indicator supplies the volatility scale used for stops, targets, and a noise filter.

The design is meant for markets that alternate between two behaviours. In some periods, direction has positive memory — trends persist, and continuation is more likely than reversal. In other periods, direction has negative memory — moves are answered by snapbacks, and mean reversion dominates. A fixed always-trend or always-revert rule tends to work in one environment and struggle in the other. This EA tries to measure which memory is currently active and switch its trading mode accordingly, rather than betting on a single fixed behaviour.

As a learning tool, this strategy suits traders who want to study regime detection, statistical thinking about price, and adaptive risk design. Because it is an original, first-principles system rather than a repackaged classic indicator, it is a useful way to explore how directional memory can be quantified. It is not a shortcut to results, and like every mechanical system it can and will experience losing streaks.

How It Works

The EA processes one newly-closed bar at a time on your chosen timeframe. On each new bar it recomputes the regime and decides whether any of its conditions are met.

directional persistence regime switch EA
Illustrative example of the strategy’s entry and exit logic — not real trading results.

Strategy Parameters

Parameter Default Min Max Description
Lookback 40 15 120 Window, in returns, used to estimate the sign-autocorrelation regime. Larger values smooth the reading; smaller values react faster.
RegimeThreshold 0.20 0.05 0.60 The \ rho\ gate — how decisive the directional memory must be before the strategy acts. Higher values demand stronger structure.
TriggerAtrFraction 0.50 0.10 1.50 The latest bar must move at least this fraction of ATR to trigger, keeping the EA off small, noisy bars.
AtrPeriod 14 7 40 Averaging period for the ATR used in the noise gate, stop, and targets.
StopAtrMult 1.50 0.50 4.00 Stop-loss distance as a multiple of ATR.
RewardTrend 3.00 1.00 6.00 Take-profit multiple (× ATR) in the trend/persistence regime — lets a move run.
RewardReversion 1.50 0.50 3.00 Take-profit multiple (× ATR) in the reversion regime — banks a quicker snapback.
Lots 0.10 0.01 1.00 Fixed order volume in lots.

There is also a Magic number (default 7731) used to identify and manage the EA's own positions.

directional persistence regime switch EA — MQL5 source code

Recommended Chart Settings

This strategy operates on a single timeframe — every calculation uses the chart's own period, so the timeframe you attach it to is the strategy's timeframe. A common starting point for study is a liquid major forex pair such as EUR/USD on the H1 (1-hour) chart, where close-to-close returns are reasonably clean and ATR behaves predictably. Higher timeframes (H1 and above) generally produce fewer, more considered signals, while lower timeframes generate more signals with more noise.

Because the regime measurement is scale-free and unit-free, it can be applied to other symbols and timeframes, but results will vary considerably across instruments and market conditions. Always test any symbol and timeframe combination on historical data and a demo account before drawing conclusions.

How to Install on MetaTrader 5

What to Consider Before Using This EA

The most interesting strength of this approach is that it does not assume a single market personality. By measuring directional memory in real time, it attempts to trade with trends when continuation is statistically favoured and against moves when reversals dominate. The adaptive reward — wider targets in trends, tighter targets on fades — reflects the different payoff geometry of the two regimes, and the ATR-based stops keep risk proportional to current volatility rather than a fixed distance.

There are important limitations to understand. The sign autocorrelation is a backward-looking statistic: it describes the memory of the past Lookback bars, and a regime can flip immediately after the strategy has classified it. Choppy, transitional markets can produce whipsaws where the EA enters just as the regime changes. The RegimeThreshold gate reduces this by standing aside when rho is weak, but no filter eliminates false signals. The strategy also acts only once per bar and holds a single position, so it can miss opportunities while a trade is open or during fast intrabar moves.

This EA may historically underperform in markets that are pure noise (rho hovers near zero and few trades trigger) or during sharp news-driven spikes that blow through ATR-based stops. It is best treated as a framework for studying regime switching — not as a finished, hands-off system. Parameter choices such as Lookback, RegimeThreshold, and the reward multiples materially change its behaviour and should be explored deliberately.

Risk Management Tips

Sound risk management matters more than any single entry rule. Consider these general principles as you study this strategy:

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

← Back to Blog