Loading…

Auto Lag Momentum

A classic momentum indicator (close[0] - close[n]) fixes n once and for all. That works fine while the market's own natural cycle length sits near n, and reads mostly noise once it drifts away - a 10-bar momentum on a market currently echoing itself every 22 bars is measuring the wrong distance. This indicator searches a configurable range of candidate lags at every bar, computes each candidate's own Pearson sample autocorrelation of returns over a trailing window (the standard cov(x[t], x[t-lag]) / var(x) estimator), and picks whichever lag has the largest absolute autocorrelation - positive or negative, since a strong negative autocorrelation (mean-reverting echo) is just as real a structural signal as a strong positive one (trending echo). Momentum is then computed as close[0] - close[chosen lag], so the distance being measured tracks the market's own recently-dominant cycle instead of an operator's fixed guess. Notes and limitations - The chosen lag can itself change from bar to bar, which means the line's scale (price difference over a variable distance) is not perfectly consistent bar-to-bar the way a fixed-lag momentum's scale is - read it as a regime/direction gauge, not a precisely calibrated distance measure. - Autocorrelation estimated from a short or unusually flat window (zero variance) is unreliable; the indicator requires InpAutocorrWindow >= 3x InpMaxLag at load time to guard against the worst of this, but a genuinely quiet market can still produce a noisy lag choice. - Not a repainting indicator - each bar's value depends only on bars at or before it.

Indicator · MT4 · v1.0 · Free

About Auto Lag Momentum

Auto Lag Momentum is an indicator for MetaTrader 4. It has 4 settings, such as Min lag, Max lag and Autocorr window. MQL source code included.

Files in the download: AutoLagMomentum.ex4, AutoLagMomentum.mq4, AutoLagMomentum.txt.

Settings

SettingDefaultWhat it does
Min lag2Smallest candidate lag tested
Max lag20Largest candidate lag tested
Autocorr window100Trailing bars used to estimate each candidate lag's autocorrelation
Max bars to process500Cap on how many bars back to (re)compute on first load

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Momentum · Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria