Loading…

Autocorrelation Lag Table Export

An autocorrelation bar chart on its own leaves the reader guessing which bars are a genuine pattern and which are exactly what a random, uncorrelated series would produce by chance. This script computes the standard sample autocorrelation coefficient for each lag - the same formula any statistics package uses, normalised against the full series variance rather than a per-lag re-normalisation that would overstate the correlation at long lags - and places the real large-sample significance bound next to every row. The bound used is +/-1.96/sqrt(N), the asymptotic 95% band for the sample autocorrelation of an uncorrelated series with N observations. It is not a cosmetic threshold picked to look reasonable; it is the textbook test, so a lag whose |autocorrelation| exceeds the bound can honestly be called statistically significant at the 95% level, and one that does not can honestly be called indistinguishable from noise. Returns can be computed as simple percent or log return. Log returns are the more standard choice for this kind of analysis since they are additive across time, and are the default. Notes and limitations - Daily timeframe only (PERIOD_D1). - The significance bound assumes the returns are approximately independent and identically distributed under the null hypothesis - a reasonable large-sample approximation, not an exact finite-sample test. With only a few hundred observations the bound is still a useful guide but treat borderline lags cautiously. - A significant lag says the return series has measurable linear dependence at that lag in the sampled history. It is not, by itself, evidence that the dependence is large enough to trade profitably after spread and commission. - The script runs once against the currently loaded history depth. Run it again after more history has downloaded if the terminal only had a short window cached.

Script · MT4 · v1.0 · Free

About Autocorrelation Lag Table Export

Autocorrelation Lag Table Export 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 Max lag, Max bars and Use log return. MQL source code included.

Files in the download: AutocorrelationLagTable.mq4, AutocorrelationLagTable.txt.

Settings

SettingDefaultWhat it does
Max lag20Highest lag to compute (trading days)
Max bars3000Daily bars to use for the return series (0 = all)
Use log returntrueUse log return instead of simple percent return
File nameAutocorrelationLagTable.csvOutput file (in MQL4\Files)

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria