Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Indicator | Rolling Return Autocorrelation Regime Oscillator | Free Download

RobotFX curates the best open-source MetaTrader code to inspire your trading automation.

A raw per-bar reading on its own is jumpy, so a second, EMA-smoothed line rides on top of it. That smoothed line is the one worth watching for regime persistence; the raw dotted line is there mainly to show how much the underlying estimate is bouncing around bar to bar.

How to interpret it

  • Smoothed line pushing above the upper band: returns are showing statistically meaningful positive autocorrelation - trend-following approaches tend to have better odds here.
  • Smoothed line pushing below the lower band: returns are showing statistically meaningful negative autocorrelation - fading extremes or range-trading tends to have better odds here.
  • Smoothed line oscillating inside the bands: no reliable serial dependence at the chosen lag - treat the market as closer to random over that window, and lean more on other tools.
  • A raw line that's swinging wildly while the smoothed line stays flat near zero is a reminder that the window is short relative to the noise - consider raising InpWindowSize .
  • A sustained crossing from below zero to above zero (or vice versa) often lines up with a genuine shift from a ranging phase into a directional one, or the reverse - it's a regime-change flag, not a trade trigger by itself.
  • Because the calculation works on returns, not price, the reading is comparable across symbols and timeframes with very different price scales.

External variables (inputs)

Input Default Purpose
InpWindowSize 50 Number of return observations in the rolling window used for each autocorrelation estimate
InpLag 1 Return lag correlated against (in bars); 1 captures bar-to-bar persistence, higher values capture slower cycles
InpSmoothPeriod 5 EMA smoothing period applied to the raw autocorrelation reading
InpConfidenceZ 1.96 Z-score used to compute the significance bands (1.96 approximates a 95% confidence level)
InpUseLogReturns true Uses log returns when true; uses simple price differences when false

Recommended use

Start with the defaults on an hourly chart and watch how the smoothed line behaves around known trending versus choppy stretches you already recognize - that builds an intuitive feel for where the bands sit on your instrument before you rely on it. Shorter windows react faster to regime shifts but produce noisier raw readings and wider significance bands (since the band scales with 1/√N); longer windows are steadier but slower to flag a change. This indicator says nothing about direction, only about the character of recent price behavior, so it's best paired with a directional or level-based tool: use it to decide whether a breakout or a fade is the higher-probability approach right now, rather than as a standalone signal generator.

Image for Rolling Return Autocorrelation Regime Oscillator
Returns from a sliding window are correlated against their own lagged values every bar, producing a regime oscillator bounded by significance bands.

Capture price channel breakouts with the Price Channel Expert Advisor. Precise entries and exits. Explore now.

Thanks for reading. Discover premium MetaTrader solutions at RobotFX.

76067

Best MetaTrader Indicators + Profitable Expert Advisors