All indicators

Cointegration

By LuxAlgoAug 9, 2026

Static chart image

Cointegration is a pairs-testing workstation in one pane — the definitive clean implementation of cointegration for chart use. Every bar it regresses 252 bars of the chart symbol's log prices on a comparison leg (default SP:SPX) for a hedge ratio, rebuilds the residual spread, z-scores it, and runs the Engle-Granger step: the spread's Dickey-Fuller statistic must beat the MacKinnon critical value to test cointegrated. A dashboard reports hedge ratio, z-score, statistic, half-life and status.

How to Trade the Cointegration?

  • Z-score beyond the entry levels: a cross above +2 is a short-spread event, below -2 a long-spread event — by default only while the pair tests cointegrated.
  • Return to the mean: exit events fire when the z-score crosses the exit threshold back toward zero.
  • Cointegration Established / Lost: transitions carry alerts; a lost relationship stands entries down — a broken pair's deviations have no reason to revert.

Cointegration Settings

  • Comparison Symbol (default SP:SPX): second leg of the pair.
  • Source (default close): price series for both legs.
  • Use Log Prices (default on): regression and spread on log levels.
  • Formation Window (default 252): bars behind regression, test and z-score.
  • Significance Level (default 5%): test strictness; critical values -3.90 / -3.34 / -3.04.
  • Plot Test Statistic (default off): plots the rolling statistic and its critical value.
  • Entry Threshold (default 2): z-score arming entry events.
  • Exit Threshold (default 0): reversion exit level; 0 waits for the full return.
  • Signals Require Cointegration (default on): gate entries on a passing test.
  • Show Signal Markers (default off): triangles on entries; alerts fire regardless.
  • Show Dashboard (default on), with position and size options.
  • Style inputs set the colors and the dimming of the spread while the pair fails the test.

Frequently Asked Questions

Is cointegration just strong correlation?

No. The Correlation Coefficient scores short-run co-movement of returns; this test interrogates levels — whether the hedge-ratio spread stays tied to a stable mean, the stationarity fading a spread depends on.

What does the half-life reading mean?

It turns the fitted reversion speed into a bar count — the expected time for half of a deviation to bleed away. A half-life approaching the formation window warns the reversion is too slow to lean on.

Which formation window should I use?

The default 252 approximates the classic one-year formation on daily charts. Stretching it buys stability at the price of clinging to broken pairs; shrinking it lets go sooner but false-alarms more.

Original indicatorBuilt in-house by LuxAlgo

The Library is free. Quant makes it yours.

Pull any concept or indicator into Quant: rebuild it, retune it, or turn it into a backtested strategy of your own.