Loading…

Autoregressive Forecast Line

Most "forecast line" indicators on public code sites either curve-fit a polynomial through recent price with no statistical basis, or draw a confident-looking projection with no error bars at all. This one fits an actual AR(p) model - price's own recent log returns regressed against their own recent lags - using the Levinson-Durbin recursion, the standard numerically stable method for solving the Yule-Walker equations without inverting a matrix by hand. It then projects exactly one bar forward and draws the model's own residual standard deviation as a confidence band around that single point. The honesty is in what gets said out loud rather than hidden: the band reflects only the model's in-sample residual noise, not the additional uncertainty that comes from the AR coefficients themselves being estimated from a finite window rather than known exactly. Real-world forecast error is therefore wider than the band shown, and a fixed red warning label says so directly on the chart rather than leaving a user to assume the band is a complete error estimate. This is a one-step-ahead statistical projection meant to show what a fitted model implies is likely, not a multi-bar price prediction and not a trading signal - the AR order and fit window are exposed specifically so it can be tuned to different symbols rather than assumed to transfer. Notes and limitations - Needs InpFitWindow + InpArOrder + 2 bars of history before the first forecast can be drawn. - The confidence band accounts only for residual noise, not parameter estimation uncertainty - actual forecast error is wider than shown. This is stated on the chart itself via the warning label. - Assumes returns are reasonably stationary over the fit window; a sudden regime change invalidates the fitted coefficients until enough new data accumulates to refit. - Projects exactly one bar ahead by design - it is not a multi-bar price path and should not be read as one. - Rebuilds only once per newly closed bar, so it will not shift intra-bar as price moves; the projection is fixed until the next close.

Indicator · MT4 · v1.0 · Free

About Autoregressive Forecast Line

Autoregressive Forecast Line is an indicator for MetaTrader 4. It has 5 settings, such as Ar order, Fit window and Confidence z. MQL source code included.

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

Settings

SettingDefaultWhat it does
Ar order3AR model order (number of lagged returns used)
Fit window150Number of past returns the model is fitted on
Confidence z1.96Z-score for the confidence band (1.96 ~ 95%)
Forecast colorclrYellowCentral forecast line colour
Band colorclrGrayConfidence band colour

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: MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria