Loading…

Cointegration Traffic Light

"These two symbols are cointegrated" is a claim that needs an actual test, not just a chart that looks like it reverts. This indicator builds a regression spread the same way a pairs-trading z-score tool does (an OLS hedge ratio between the chart symbol and InpSecondSymbol over InpRegressionWindow bars), then runs a Dickey-Fuller test on the spread's own trailing InpDfWindow bars: regress the spread's bar-to-bar change on its own lagged level, and take the t-statistic of that slope. A more negative t-statistic is stronger evidence the level series pulls back toward its own mean rather than wandering like a random walk - the standard unit-root logic behind every ADF-based cointegration test. HONEST ABOUT WHAT IS SIMPLIFIED: this is a plain Dickey-Fuller regression, not an Augmented one - it has no lagged-difference terms added to whiten serial correlation in the residuals, which is what the "Augmented" in ADF normally buys you on data with its own autocorrelation structure. The critical values used (InpCritical1pct / InpCritical10pct, -3.5 and -2.6 by default) are the commonly published approximate Dickey-Fuller thresholds for this sample-size range, not a table looked up for the exact window length. Treat the traffic light as a genuine statistical test with an honestly simplified specification - useful for tracking whether a pair's mean-reversion behaviour is currently holding up - not as a precise MacKinnon p-value suitable for academic citation. The light is recomputed on every closed bar and shown both as a plotted t-statistic (coloured by tier via the split-buffer trick, since MQL4 has no DRAW_COLOR_* line types) and as a plain-language panel label, with an optional alert when the light changes colour. Notes and limitations This is a plain (non-augmented) Dickey-Fuller test - see the full description above for exactly what that omits versus a true ADF test. The hedge ratio is a simple OLS beta with no intercept, recomputed fresh over each InpRegressionWindow rather than tracked incrementally; a spread built from a genuinely unstable hedge ratio can flip the light frequently even when the underlying relationship is real, since the regression window itself is reacting to the same price action. As with any pairs tool in this catalogue, both symbols are read at the SAME shift index, which is accurate when both share the chart's timeframe and closely aligned session hours, and only approximate otherwise.

Indicator · MT5 · v1.0 · Free

About Cointegration Traffic Light

Cointegration Traffic Light is an indicator for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 11 settings, such as Second symbol, Symbol suffix and Regression window. MQL source code included.

Files in the download: CointegrationTrafficLight.ex5, CointegrationTrafficLight.mq5, CointegrationTrafficLight.txt.

Settings

SettingDefaultWhat it does
Second symbolGBPUSDSecond leg of the pair (the chart's own symbol is the first leg)
Symbol suffixBroker suffix appended to InpSecondSymbol, leave blank if none
Regression window100Bars the hedge-ratio regression and the spread itself are built over
Df window60Trailing spread bars the Dickey-Fuller regression itself uses (<= InpRegressionWindow)
Critical1pct-3.5Approximate DF critical value, ~1% (t-stat at/below this = GREEN)
Critical10pct-2.6Approximate DF critical value, ~10% (t-stat above this = RED)
CornerCORNER_LEFT_UPPERPanel corner
X distance10Panel horizontal offset, pixels
Y distance20Panel vertical offset, pixels
Font size10Panel font size
AlertstrueAlert once per closed bar when the light changes colour

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Hedging · Trailing Stop & Break-even · Alerts · MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria