Volatility Clustering Persistence Study
"Volatility clusters" is repeated as received wisdom - a big move tends to be followed by more big moves, not an immediate return to calm - but it is rarely checked with the actual statistic that supports it. A raw return's autocorrelation is close to zero at every lag (returns themselves are close to unpredictable); the textbook signature of clustering is that the autocorrelation of the return's MAGNITUDE stays positive for many lags. This script builds that series and computes it properly: mean-centred sample autocorrelation of |log return| at every lag from 1 to InpMaxLag, using the full-sample variance as the denominator, not a rough proxy. The single number most traders actually want from this is not the whole table - it is "how long does it last". The script finds that directly as a half-life: the first lag at which the autocorrelation has decayed to half of its lag-1 value. That is the figure a volatility filter's lookback window or cooldown period should be built around, rather than a round number picked by feel. Returns are built as log returns over consecutive completed bars on the requested timeframe, oldest to newest, so the lag-k comparison always compares genuinely k bars apart regardless of how the array happens to be indexed. Notes and limitations This is a historical base-rate study, not a live volatility-regime detector. It describes how the SAMPLE behaved over the studied window; a different window (different years, different symbol conditions) can give a materially different half-life. If the lag-1 autocorrelation is not positive, no half-life exists and the script reports "not reached" rather than a misleading number - decay from a value that never rose in the first place is not clustering. A day with genuinely zero price variance across the whole studied window (a flat/dead series) is rejected outright rather than reported as a degenerate autocorrelation of zero.
Script · MT4 · v1.0 · Free
About Volatility Clustering Persistence Study
Volatility Clustering Persistence Study is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Timeframe, Bars to study and Max lag. MQL source code included.
Files in the download: VolatilityClusteringStudy.mq4, VolatilityClusteringStudy.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Timeframe | PERIOD_H1 | Timeframe the returns are built from |
| Bars to study | 2000 | Completed bars used to build the return series |
| Max lag | 20 | Highest lag tested (in bars) |
| Save csv | true | Write the full lag/ACF table to a CSV file |
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 → Scripts.
- 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 script onto a chart to run it once.
Tags: Alerts · MT4 Script · MQL4 Source Code