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?
Recurrence Range Reversion is a mean-reversion trading strategy whose defining feature is a Recurrence Quantification Analysis (RQA) regime filter — a technique borrowed from nonlinear dynamics that measures how often a price trajectory revisits states it has already occupied. Where most mean-reversion systems simply fade a price that has stretched too far from an average, this strategy adds a statistical gate that asks a deeper question first: is the market actually behaving like a range right now?
The reasoning is grounded in a well-known weakness of mean reversion. Fading a stretched price only pays when the market is stationary — that is, when it keeps returning to the same value region. The same behaviour becomes damaging when a range quietly resolves into a trend, because a fade placed against a breakout can be run over. Common "flat regime" filters such as ADX, flat moving-average slope, or low volatility are blind to that distinction. The recurrence rate measures it directly by embedding recent closes into a two-dimensional phase space and counting how many of the resulting state vectors fall close to one another. A high recurrence rate says the trajectory keeps looping back on itself (a range worth fading); a low rate says the trajectory is escaping (a trend to stand aside from).
As a learning tool, this strategy is well suited to traders who already understand basic mean reversion and want to see how a research-grade regime filter can be layered on top of it. It is designed for range-prone conditions on FX majors such as EUR/USD or AUD/USD on intraday timeframes, but nothing in the code hardcodes a symbol or timeframe. Treat it as a case study in when to apply mean reversion, not merely how.
How It Works
The strategy refreshes its regime measurements once per completed bar and manages open trades on every tick. All calculations are derived from raw closing prices and z-scored, so the measure is unit-independent across symbols and timeframes.
Building the regime measure:
- The last
RecurWindowcloses are z-scored (mean subtracted, divided by standard deviation) so the phase space is scale-free. - Those z-scores are time-delay embedded into 2-D state vectors of the form
V[k] = ( z[k], z[k-tau] ), wheretauis theEmbedDelay. An oscillating market traces loops that revisit the same neighbourhood; a trending market drifts along the diagonal and never returns. - The Recurrence Rate (RR) is the fraction of all state-vector pairs whose Euclidean separation is smaller than the radius
RecurEps. A high RR signals a recurring, range-bound regime; a low RR signals a trend or breakout.
Entry conditions (only while RR is at or above RecurRateMin):
- Long: the just-closed bar sits below the window mean by at least
StretchAtr× ATR and prints a bullish reaction candle (close above open). The strategy signals a fade of the dip back toward fair value. - Short: the exact mirror — the close is stretched above the mean by at least
StretchAtr× ATR and the bar prints a bearish reaction candle (close below open). - Only one fade is held at a time per magic number; the stop, target, and regime guard manage it from there.
Exit and risk logic:
- Stop-loss: placed
StopAtr× ATR beyond the reaction bar's extreme — below the bar's low for longs, above the bar's high for shorts. This keeps per-trade risk structurally tight. - Take-profit: set to the window mean, which is the value the recurring regime keeps returning to.
- Break-even lock: once price advances
BreakevenAtr× ATR in your favour, the stop is pulled to the entry price so a winner may no longer turn into a loser. - Regime guard (drawdown control): if the recurrence rate collapses below
RecurRateMinwhile a fade is live, the position is closed at market. The interpretation is that the range has broken, so the strategy exits before a potential trend move develops.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| RecurWindow | 48 | 20 | 120 | Number of closes used to build the phase space and the reversion mean. |
| EmbedDelay | 2 | 1 | 6 | Embedding delay tau (in bars) for the 2-D state vectors. |
| RecurEps | 0.35 | 0.10 | 1.00 | Recurrence radius epsilon in z-score units; two states "recur" if closer than this. |
| RecurRateMin | 0.15 | 0.03 | 0.60 | Minimum recurrence rate (0–1) required to treat the regime as range-bound. |
| AtrPeriod | 14 | 5 | 40 | ATR period used for the volatility-scaled stretch, stop, and break-even. |
| StretchAtr | 1.6 | 0.5 | 4.0 | How far (× ATR) the close must sit from the mean before a fade is signalled. |
| StopAtr | 1.0 | 0.3 | 3.0 | Stop distance (× ATR) beyond the reaction bar's extreme. |
| BreakevenAtr | 0.8 | 0.2 | 3.0 | Advance (× ATR) in your favour before the stop is pulled to break-even. |
| Lots | 0.10 | 0.01 | 1.00 | Trade volume in lots. |
| Magic | 5271 | 0 | 9,999,999 | Magic number that identifies this EA's positions. |

Recommended Chart Settings
Recurrence Range Reversion was designed with range-prone FX majors in mind — pairs such as EUR/USD and AUD/USD — on intraday timeframes in the M15 to H1 range, where mean-reversion behaviour tends to be more pronounced. Because every calculation is scale-free and every bar reference uses the primary timeframe, the strategy is not hardcoded to any one instrument and can be tested elsewhere. Keep in mind that recurrence structure varies enormously between markets and sessions, so results will differ across symbols, timeframes, and market conditions. Always validate on the specific instrument you intend to study.
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 this approach is that it targets a genuine, well-documented weakness of mean reversion: it only fades when the market's recent trajectory is statistically confirmed to be recurring. The RQA gate is a more direct measure of stationarity than trend-strength proxies like ADX, and the regime guard is designed to cut a fade the moment recurrence collapses — an explicit attempt to keep drawdown contained when a range breaks.
There are real limitations to weigh, however. Recurrence quantification is sensitive to its own parameters: the window length, embedding delay, and radius (RecurEps) all reshape what counts as "recurring," and poorly chosen values can make the gate either too permissive or so strict it rarely trades. Like all mean-reversion systems, it is structurally exposed to sustained trends and sharp breakouts; the regime guard mitigates but cannot eliminate that risk, because a violent move can gap through the stop before the gate reacts. The recurrence rate is a lagging measure computed on closed bars, so it confirms a broken range shortly after the break begins. Finally, thin liquidity, news spikes, and widening spreads can distort both the ATR-scaled distances and the fills. This EA is best treated as an educational framework for studying regime-aware reversion rather than a finished, hands-off system.
Risk Management Tips
Sound risk management matters more than any single indicator. Consider these general principles as you study the strategy:
- Position sizing: size trades so that a single loss is a small, survivable fraction of your account rather than a threat to it.
- The 1–2% rule: many educators suggest risking no more than 1–2% of account equity on any one trade, so a string of losses does not compound into serious damage.
- Use a demo account first: test the strategy in a risk-free simulated environment until you understand its behaviour across trending and ranging conditions.
- Understand drawdown: every strategy endures losing streaks. Know the historical depth and duration of drawdown you may face, and confirm you can tolerate it emotionally and financially.
- Account for costs: spreads, commissions, and slippage all erode mean-reversion edges, which typically target modest moves back to a mean.
- Never over-leverage: leverage magnifies losses as readily as gains; keep it conservative while you learn.
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: RecurrenceRangeReversion.ex5 (19 downloads)
- Source Code: RecurrenceRangeReversion.mq5 (20 downloads)
- Documentation: RecurrenceRangeReversion.pdf (27 downloads)