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 Mean Crossing Cadence Regime strategy is a regime-switching Expert Advisor (EA) for MetaTrader 5 built around a single, unusual measurement called the mean-crossing cadence — the rate at which price crosses back and forth over its own recent average. Rather than borrowing from any named indicator, chart pattern, or popular methodology, it draws on a concept from signal-processing theory known as level-crossing analysis (Rice's formula) and applies it directly to the closing-price series. In plain terms, it counts how often price flips from one side of its local mean to the other and uses that count to decide whether the market is currently "bouncy" (mean-reverting) or "sticky" (trending).
Because the same statistic both classifies the market and points to a trade direction, the strategy is entirely self-arbitrating: one number chooses the playbook, and price's position relative to its mean chooses the side. When crossings are frequent, the strategy treats large deviations as temporary and fades them back toward the mean. When crossings are rare, it treats a fresh crossing as the ignition of a new directional leg and follows it. Volatility is measured using the mean-absolute-deviation (MAD) of the window and the Average True Range (ATR), so stops and targets adapt as market conditions breathe.
This EA is best viewed as a learning tool for traders who want to understand adaptive, regime-aware logic and how a market's oscillation frequency can inform tactics. It is designed with FX majors and metals on M5–H1 timeframes in mind, but it locks to no specific timeframe. It is not a shortcut to results and is not suitable as a set-and-forget system without study, testing, and supervision.
How It Works
The strategy acts once per newly closed bar on the chart's timeframe. On each closed bar it recalculates its window statistics and then evaluates whether the current regime is mean-reverting or trending.
- Building the window: The EA takes the last N closed closing prices (default 40) and computes their arithmetic mean. Each bar's deviation from the mean is
d = close − mean. - Measuring cadence (κ): It counts how many times the sign of
dflips across the window and divides byN − 1. This ratio, κ (kappa), ranges from 0 to 1 and represents the dominant oscillation frequency — how often price crosses its own mean. - Regime classification: If κ is at or above the
CadenceThreshold(default 0.35), the market is treated as a high-frequency, mean-reverting regime. If κ is below the threshold, it is treated as a low-frequency, trending/persistent regime. - Volatility yardstick: The window's mean-absolute-deviation (MAD) is used to express the current stretch as a dimensionless score
z = d_now / MAD, while ATR (default period 14) sets the distance of stops and targets.
Mean-reverting regime — fade the stretch (target the mean):
- If price is stretched above the mean by at least
EntryZMAD units (z ≥ +EntryZ), the strategy signals a SELL, targeting the mean itself as a "magnet" and placing a stopAtrStopMult × ATRabove entry. - If price is stretched below the mean by at least
EntryZunits (z ≤ −EntryZ), the strategy signals a BUY, targeting the mean, with a stop the same ATR distance below entry. - A minimum reward-to-risk filter (
MinRewardRisk) rejects fades where the mean target is already too close to justify the ATR-based stop.
Trending regime — follow a fresh mean crossing:
- If the previous bar's deviation was negative and the current one is positive (a fresh up-crossing), the strategy signals a BUY, with a take-profit
TrendTpMult × ATRabove entry. - If the previous deviation was positive and the current one is negative (a fresh down-crossing), the strategy signals a SELL, with a take-profit the same ATR distance below entry.
- In both trend cases the stop is placed
AtrStopMult × ATRon the protective side of entry.
Exit and position management: Every trade carries a hard stop-loss and take-profit at the moment it is opened, so the broker-side orders manage all exits. The EA holds one position per magic number at a time and skips new entries when the current spread exceeds MaxSpreadPoints, helping avoid entries during unusually wide, illiquid conditions.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| LookbackN | 40 | 15 | 90 | Number of closed bars used to compute the mean and the crossing cadence κ. |
| CadenceThreshold | 0.35 | 0.15 | 0.60 | κ at or above this value = mean-reverting regime; below = trending regime. |
| EntryZ | 1.6 | 0.8 | 3.0 | Fade trigger: how many mean-absolute-deviation units price must be stretched from the mean. |
| AtrPeriod | 14 | 5 | 30 | Lookback period for the ATR used to size stops and targets. |
| AtrStopMult | 2.0 | 0.5 | 4.0 | Stop-loss distance as a multiple of ATR. |
| TrendTpMult | 2.5 | 0.5 | 5.0 | Trend-regime take-profit distance as a multiple of ATR beyond entry. |
| MinRewardRisk | 0.7 | 0.3 | 3.0 | Rejects fades whose mean target is closer than this fraction of the ATR stop distance. |
| MaxSpreadPoints | 60 | 5 | 300 | Skip new entries when the current spread (in points) exceeds this value. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade volume in lots. |
| Magic | 5417 | 0 | 9,999,999 | Magic number identifying this EA's positions. |

Recommended Chart Settings
The Mean Crossing Cadence Regime EA was designed with FX majors and metals (for example EURUSD, GBPUSD, or XAUUSD) in mind, on timeframes from M5 through H1. Because the cadence statistic and MAD/ATR yardsticks are self-scaling, the logic is not hard-wired to a single timeframe — it runs on whatever chart period you attach it to. That said, different symbols and timeframes will produce very different crossing frequencies, so the CadenceThreshold that separates ranging from trending behavior may need to be re-tuned per market. Results will vary across different market conditions, brokers, and spread environments, and any settings should be validated on your own data before use.
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 conceptual strength of this approach is that it does not assume the market is always trending or always ranging. By reading the mean-crossing cadence, it attempts to adapt its tactics to whichever regime is present, and it uses robust, distribution-free volatility measures (MAD and ATR) rather than assuming prices are normally distributed. Because every trade is opened with a defined stop and target, risk on each position is bounded from the outset.
There are, however, meaningful limitations to understand. Regime classification from a single statistic is inherently noisy: κ can sit near the threshold and flip between regimes on consecutive bars, producing whipsaw between fade and follow logic. The strategy also acts only on closed bars, so it may enter after a portion of a move has already occurred. Mean-reversion fades can suffer during strong, sustained trends where price stretches far beyond the mean and keeps going, while the trend-following branch can be caught out during choppy, false breakouts of the mean. Fixed-lot sizing does not scale risk to account equity or volatility, and the spread filter, while helpful, does not protect against slippage during news. As with any strategy, historically favorable behavior in one market or period may not repeat in another.
Risk Management Tips
- Test on a demo account first. Run the EA in MT5's Strategy Tester and on a demo account across multiple symbols and market conditions before considering any live use.
- Size positions conservatively. A common educational guideline is to risk no more than 1–2% of account equity on any single trade. Because this EA uses a fixed lot size, review whether the resulting risk per trade fits your account.
- Understand drawdown. Even a well-behaved strategy can experience extended losing streaks. Study the maximum drawdown in testing and ask yourself whether you could tolerate it emotionally and financially.
- Account for costs. Spread, commission, and swap can materially change outcomes, especially on lower timeframes with frequent trades.
- Supervise, don't abandon. Automated does not mean unattended. Monitor performance and be prepared to disable the EA during major news events or abnormal market conditions.
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: MeanCrossingCadenceRegime.ex5 (0 downloads)
- Source Code: MeanCrossingCadenceRegime.mq5 (0 downloads)
- Documentation: MeanCrossingCadenceRegime.pdf (0 downloads)