Garch Volatility Forecast
ATR and its relatives measure volatility that has already happened. GARCH is a forecasting model: it says that tomorrow's variance is a weighted blend of a long-run average, the size of today's move squared, and today's own variance estimate - sigma2(t) = omega + alpha*r(t)^2 + beta*sigma2(t-1). That recursive structure is what lets it react immediately to a volatility shock while still decaying back toward the long-run average afterward, which a fixed-window average range measure cannot do. Fitting a GARCH model properly is a maximum-likelihood optimisation, which is not something worth re-running inside OnCalculate on every tick. This implementation uses variance targeting instead: the long-run variance is measured directly from the trailing InpLookback window, omega is derived from it once alpha and beta are chosen, and a small grid search over alpha/beta picks the pair that minimises one-step-ahead squared forecast error across that window. The fit is re-run every InpRefitEvery closed bars, not every tick, and the forecast recursion itself only advances on a closed bar - the naive version of this indicator either fits nothing at all and just calls itself GARCH, or re-optimises every tick and drags the chart down. A simple rolling realised-volatility line (plain standard deviation of returns over InpRealizedWindow bars) is plotted alongside the forecast so the two can be compared directly: a forecast that consistently sits above realised volatility during a calm patch is pricing in mean-reversion toward a higher long-run level, and a forecast that spikes ahead of realised volatility during a shock is the model doing what GARCH is for. Notes and limitations - The forecast for the still-forming bar is fixed the moment the previous bar closes and does not change intrabar - it depends only on already-closed data by design, so it will not move tick to tick. - Variance targeting with a small alpha/beta grid is a practical approximation of full maximum-likelihood GARCH fitting, not a replacement for it - treat the parameters as reasonable, not optimal. - The oldest bars near the start of the chart's available history are a burn-in period: the recursion is seeded with a long-run variance estimate there and needs a few hundred bars to settle, so early history should not be read closely. - This forecasts variance, not direction - it says nothing about which way price is likely to move, only how much it may move.
Indicator · MT5 · v1.0 · Free
About Garch Volatility Forecast
Garch Volatility Forecast is an indicator for MetaTrader 5. It has 3 settings, such as Lookback, Refit every and Realized window. MQL source code included.
Files in the download: GarchVolatilityForecast.ex5, GarchVolatilityForecast.mq5, GarchVolatilityForecast.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback | 250 | Bars of history used to fit and seed the GARCH recursion |
| Refit every | 20 | Closed bars between parameter re-estimations |
| Realized window | 10 | Bars averaged for the comparison realised-volatility line |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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: ATR · MT5 Indicator · MQL5 Source Code