Discussing the article: "Testing Random Walk vs Mean Reversion in MQL5: Implementing the Lo-MacKinlay Variance Ratio Test"

Check out the new article: Testing Random Walk vs Mean Reversion in MQL5: Implementing the Lo-MacKinlay Variance Ratio Test.

Implements the Lo–MacKinlay Variance Ratio Test in MQL5 to assess serial dependence via random‑walk variance scaling. Provides a reusable CVarianceRatio class with classical (homoskedasticity) and heteroskedasticity‑robust statistics, plus a script that scans multiple horizons and logs VR and Z‑values. Shows how to embed the test in an Expert Advisor as a statistical gate for mean‑reversion logic.

Most trading strategies rely on some assumption about price behavior. Mean-reversion strategies expect prices to return to a reference level. Breakout strategies bet on continuation after a range break. Both can work—until market conditions shift. When that happens, a strategy optimized for one regime often fails in another.

A price chart alone can't formally validate these assumptions. Indicators like RSI or Bollinger Bands describe recent price behavior, but they don't test whether returns actually exhibit the serial dependence a strategy expects. An oversold RSI reading doesn't guarantee mean-reversion—it just shows where price sits relative to recent history. So let's step back and ask a more fundamental question: are return increments consistent with the variance-scaling implication of a random-walk or martingale-difference null, or is there measurable dependence across different holding horizons?

Here, we'll implement the Lo-MacKinlay Variance Ratio Test (1988) in MQL5. The test checks whether the variance of k-period returns scales the way a random-walk or martingale-difference null implies it should—specifically, whether the variance of k-period returns grows proportionally with k.

Author: Kayode Michael Oyetunde