Variance Ratio Test
If price truly followed a random walk, the variance of a q-bar return would be exactly q times the variance of a 1-bar return - variance scales linearly with the holding period under the null hypothesis. The variance ratio VR(q) is that q-bar variance divided by q times the 1-bar variance, computed from overlapping q-bar sums the way Lo and MacKinlay's original 1988 test specifies, which uses the available sample more efficiently than a non-overlapping block estimate would. VR(q) above 1 means multi-bar moves compound faster than the random walk null predicts - positive autocorrelation, the statistical signature of momentum. VR(q) below 1 means the opposite - later bars partly reverse earlier ones, the signature of mean reversion. The indicator also reports a z-score built from the standard homoskedastic asymptotic variance of the estimator, and marks any bar where that z-score exceeds InpSignificanceZ in magnitude, so a trader can tell a genuine departure from a random walk apart from ordinary sampling noise. The homoskedastic assumption behind the z-score is a real simplification: markets cluster volatility, and that clustering alone can push VR(q) away from 1 without any genuine autocorrelation present. Treat the significance marker as a useful filter, not statistical proof. Notes and limitations - The z-score assumes homoskedastic (constant-variance) returns; real markets exhibit volatility clustering, which biases the test toward over-stating significance during quiet-to-volatile transitions. - InpQ is capped at a quarter of InpLookback in the input validation, since the overlapping estimator needs enough independent blocks to be meaningful at the chosen horizon. - This tests one specific horizon at a time; a market can show VR(q) near 1 at one q and a clear departure at another. - This is a statistical read of recent history, not a forecast, and does not size a position or account for trading costs.
Indicator · MT5 · v1.0 · Free
About Variance Ratio Test
Variance Ratio Test is an indicator for MetaTrader 5. It draws buy and sell arrows on the chart and can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Lookback, Q and Significance z. MQL source code included.
Files in the download: VarianceRatioTest.ex5, VarianceRatioTest.mq5, VarianceRatioTest.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback | 200 | Sample size (number of 1-bar returns) feeding the test |
| Q | 4 | Aggregation horizon, bars, for the multi-bar variance |
| Significance z | 1.96 | |z| at or above this marks a significant departure from a random walk |
| Alerts | true | Alert once per closed bar on a new significant reading |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Buy/Sell Arrows · Alerts · MT5 Indicator · MQL5 Source Code