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 Variance Ratio Trend Regime strategy is a regime-gated momentum system for MetaTrader 5 built around the Lo & MacKinlay Variance Ratio test — a classic statistical measure of whether price movement is a random walk or shows exploitable structure. Unlike a moving-average crossover or an oscillator, the variance ratio is not a charting indicator at all; it is a formal test that tries to answer one precise question before any trade is considered: is this market currently trending, or is it just noise?
The core idea comes from a simple property of random walks. For a purely random price series, the variance of returns grows in a straight line with the holding horizon — the variance of returns measured over five bars should be about five times the variance measured over one bar. When you divide the two, you get a number close to 1. When shocks persist (a trending regime), the ratio climbs above 1. When shocks reverse (a choppy, mean-reverting regime), it falls below 1. The Variance Ratio Trend Regime strategy only looks for entries when this ratio confirms a trending regime, then uses a short-term drift measurement and a continuation candle to pick direction.
This makes it a useful learning tool for anyone studying trend-following and momentum trading, statistical filters, and the concept of "market regimes." It is designed for liquid instruments — FX majors, indices, or metals — on intraday timeframes such as M15 to H1. It suits traders who want to understand why a momentum system might stand aside in a sideways market rather than one who simply wants a set-and-forget robot. Treat it as a study of how a statistical gate can filter naive momentum, not as a shortcut to results.
How It Works
The strategy evaluates conditions once per newly closed bar on the chart's primary timeframe. It never acts on a partially formed bar, which reduces noise and repainting concerns. Here is how the logic flows:
- Regime gate (the variance ratio): On each closed bar, the strategy computes the variance ratio
VR(q)over a rolling window of log returns (VrWindowcloses, horizonVrLag). It then checks whetherVR − 1is at leastVrThreshold. If the market fails this test — meaning it looks like a random walk or a mean-reverting chop — no trade is taken and the strategy stands aside. - Direction from drift: When the regime is confirmed as trending, direction is set by recent drift — the current close compared with the close
MomentumBarsbars ago. Upward drift argues for longs; downward drift argues for shorts. - Continuation candle confirmation: The just-closed bar must agree with the drift. For a long, the bar must have closed bullish (close above open); for a short, it must have closed bearish. This filters out exhaustion spikes that close against the prevailing move.
- Long entry — the strategy signals a buy when the regime is trending, drift is positive, and the last closed candle is bullish.
- Short entry — the strategy signals a sell when the regime is trending, drift is negative, and the last closed candle is bearish.
- Spread filter: If the current spread is wider than
MaxSpreadPoints, the entry is skipped to avoid trading in poor conditions. - One position at a time: Only one position per magic number is allowed. While a trade is open, no new entries are considered; the stop and target manage the exit.
- Stop-loss logic: The stop is placed at a distance of
AtrSlMult × ATRfrom entry, using the Average True Range (ATR — a volatility measure) at the closed bar. This adapts the stop to current volatility rather than using a fixed pip distance. - Take-profit logic: The target is placed at
AtrTpMult × ATRfrom entry. With the default multipliers, the reward distance is larger than the risk distance, giving a reward-to-risk skew greater than 1:1 on each signal.
Because every calculation uses the chart's own symbol and timeframe, the strategy runs on whatever chart you attach it to. Nothing is hard-coded to a single market.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| VrWindow | 80 | 40 | 200 | Number of closes (rolling sample of 1-period log returns) used to estimate the variances. |
| VrLag | 5 | 2 | 15 | Horizon q of the variance ratio — how many bars a "shock" is measured over. |
| VrThreshold | 0.15 | 0.0 | 1.0 | Minimum (VR − 1) required to classify the regime as "trending" and allow trades. |
| MomentumBars | 10 | 3 | 40 | Lookback in bars for the drift that sets trade direction. |
| AtrPeriod | 14 | 7 | 30 | ATR length used for the stop-loss and take-profit distances. |
| AtrSlMult | 2.0 | 1.0 | 4.0 | Stop-loss distance as a multiple of ATR. |
| AtrTpMult | 3.0 | 1.0 | 6.0 | Take-profit distance as a multiple of ATR. |
| MaxSpreadPoints | 80 | 5 | 300 | Skip new entries when the current spread (in points) is wider than this. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed lot size for each position. |
| Magic | 8317 | 0 | 9,999,999 | Magic number used to identify and manage this EA's positions. |

Recommended Chart Settings
The Variance Ratio Trend Regime strategy was designed with liquid instruments in mind — FX majors (such as EUR/USD or GBP/USD), major indices, or metals like gold — on intraday timeframes between M15 and H1. These timeframes give the rolling return window enough clean data to estimate the variance ratio while still producing a reasonable number of signals.
That said, the strategy is not locked to any single market. It reads whatever symbol and timeframe you attach it to, so you are free to study its behavior across different instruments. Keep in mind that results will vary considerably across market conditions, sessions, and instruments. A regime filter that behaves well on a trending index may behave very differently on a range-bound cross. Always test any configuration on historical data and a demo account before considering it further.
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
Strengths of this approach. The most interesting feature of this strategy is its honesty about when not to trade. Naive momentum systems tend to bleed capital in sideways markets because they keep firing signals into noise. By requiring a statistically trending regime before any entry, the Variance Ratio Trend Regime strategy tries to sidestep exactly those conditions. The variance ratio is also a horizon-weighted blend of autocorrelations, which historically makes it a more robust trend gauge than a single moving-average slope. Combining the regime gate with a drift direction and a continuation candle adds two independent layers of confirmation, and the ATR-based stops adapt to changing volatility.
Known limitations. No filter is perfect. The variance ratio is a lagging, backward-looking statistic — it describes the recent window, not the next bar, so regimes can flip after the strategy has already committed to a trade. In fast-reversing markets, momentum entries can be caught at the tail end of a move (the classic risk of any trend-follower). The strategy also uses fixed-lot sizing and takes only one position at a time, so it does not scale exposure to account equity or volatility on its own. Overlapping q-period returns, used to estimate variance, are statistically noisy on short windows, and choosing VrWindow or VrLag too small can make the gate unstable.
Where it may underperform. Choppy, low-volatility ranges that never build a persistent trend, news-driven whipsaws, and thin or high-spread conditions are all environments where a momentum-after-confirmation approach can give back gains. The spread filter helps with the last of these, but it cannot eliminate slippage or gaps. Treat every parameter as a hypothesis to be tested, not a setting to trust blindly.
Risk Management Tips
Sound risk management matters more than any single entry rule. As you study this strategy, keep these general principles in mind:
- Risk a small, fixed fraction per trade. Many educational sources suggest risking no more than 1–2% of account equity on any single position. Because this EA uses a fixed lot size, you may need to adjust
Lotsso the ATR-based stop distance corresponds to that fraction on your account. - Understand your drawdown tolerance. Even a well-designed regime filter will produce losing streaks. Decide in advance how much peak-to-trough decline you are willing to accept, and study historical drawdown before committing real capital.
- Start on a demo account. Run the strategy on a demo or paper account first to observe how the regime gate behaves in live conditions across different sessions and news events.
- Mind position sizing and leverage. Leverage amplifies both gains and losses. Smaller sizing gives you more room to survive an adverse regime shift.
- Review and adapt. Markets change. A configuration that suited one period may not suit the next, so revisit your assumptions periodically rather than assuming past behavior will persist.
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: VarianceRatioTrendRegime.ex5 (32 downloads)
- Source Code: VarianceRatioTrendRegime.mq5 (34 downloads)
- Documentation: VarianceRatioTrendRegime.pdf (38 downloads)