VarianceRatio
VarianceRatio (VR, Lo and MacKinlay’s variance ratio) shows whether price moves continue over a scale of several bars or reverse. Around 1 is a random walk, above 1 is a trend, below 1 is mean reversion. The indicator helps choose a strategy: trend-following or mean reversion.
The indicator is drawn in a separate area below the chart.
How to read it
What the line shows is set by the Show parameter:
- Ratio — the VR value itself; the level 1 is the border between a trend and mean reversion;
- z-statistic — the same difference from a random walk in units of the estimate’s error: an absolute value above 1.96 means the difference is noticeable over the window.
With VR above 1 trend-following strategies fit, with VR below 1 mean-reversion strategies do.
The z-statistic is a scale, not a strict statistical test: overlapping windows and changing volatility inflate it.
How it is calculated
- The logarithmic changes of the price set in Source over the last Window bars are taken.
- The variance of the changes over Lag bars is divided by the variance of one-bar changes multiplied by the lag. For a random walk this ratio equals 1.
- In the z-statistic mode the deviation of VR from 1 is divided by its expected error for this window and lag.
The first value appears on bar number “window + 1” — the 201st with the default settings. If Window is less than Lag + 1, it is raised to Lag + 1. If the price is zero or below, or did not change over the whole window, the line breaks.
Parameters
| Parameter | Description | Default |
|---|---|---|
| Lag | Changes over this many bars are compared with one-bar changes. At least 2. | 4 |
| Window | How many last bars are in the estimate; fewer is noisier. At least 10. | 200 |
| Source | The bar price used in the calculation: Close — the close, Median — (High + Low) / 2, Typical — (High + Low + Close) / 3. | Close |
| Show | Ratio or z-statistic. | Ratio |
Plots
| Parameter | Description | Default |
|---|---|---|
| VR | The variance ratio or its z-statistic. | Orange, solid, width 1 |
Levels
The levels are visible in the settings and on the chart only in their mode.
| Parameter | Description | Default |
|---|---|---|
| Random walk | Neither a trend nor reversion. Ratio mode. | 1, blue |
| Trend | A noticeable trend. z-statistic mode. | 1.96, blue |
| Reversion | A noticeable mean reversion. z-statistic mode. | −1.96, blue |
Style
The VR line has the Plot (show the line), Label (show the last value on the right scale), Color, Width (1–5) and Style (Solid, Dashes, Dots) fields.
Each level has the Show, Value, Color, Width and Style fields. A visible level shows its value on the right scale.
How to add an indicator to the chart is described in Adding an indicator; parameters are changed in the indicator manager.