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
| Setting | Default | What it does |
|---|---|---|
| Min lag | 2 | Smallest candidate lag tested |
| Max lag | 20 | Largest candidate lag tested |
| Autocorr window | 100 | Trailing bars used to estimate each candidate lag's autocorrelation |
| Max bars to process | 500 | Cap on how many bars back to (re)compute on first load |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 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: Momentum · Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code