PROTECTED SOURCE SCRIPT
Cointegration Indication

This indicator is inspired by Nobel Prize–winning research (Engle & Granger, 1987). The core idea is simple but powerful: even if two markets look noisy on their own, their relationship can be surprisingly stable over the long run. When they drift apart, history suggests they often snap back together and that’s exactly where opportunities arise.
What this tool does is bring that theory into practice. It estimates a long-run equilibrium between two assets (Y ~ α + βX), calculates the residual spread (ε), and then evaluates whether that spread behaves in a mean-reverting way. The Z-Score tells you when the spread has moved far from its historical mean. The Error Correction Model (ECM) adds a second layer: it checks whether the spread tends to close again, and how strong that adjustment pressure is. If λ is negative and stable, the relationship is cointegrated and mean-reverting. If not, the pair is unstable — even if the Z-Score looks attractive.
Signals are summarized clearly:
– Strong Setup appears when we see both extreme divergence and a stable, negative λ.
– Weak Setup means only partial confirmation.
– Invalid means the relationship is breaking down.
Why this matters
Cointegration analysis is widely used by institutional desks, especially in pairs trading, statistical arbitrage, and risk management. Classic cases include equity index futures vs ETFs (Alexander, 2001), oil vs energy stocks (Chen & Huang, 2010), or swap spreads in fixed income (Tsay, 2010). In crypto, temporary cointegration has been observed between BTC and ETH in periods of high liquidity (Corbet et al., 2018). With this indicator, you can explore these relationships directly on TradingView, test asset pairs, and see when divergences become statistically significant.
Limitations to keep in mind
– Timeframe choice matters: Daily calculations are usually more stable; weekly or intraday often show unstable signals. To avoid confusion, you can fix the calculation timeframe in the settings.
– Cointegration is not permanent. Structural breaks (earnings, regulation, macro shifts) can destroy old relationships.
– Results are approximate. Rolling regressions, Z-Scores, and ECM estimates are sensitive to the length of the chosen windows.
– This is a research tool — not a ready-made trading system. It should be used as one piece in a broader framework.
References
Alexander, C. (2001). Market models: A guide to financial data analysis. Wiley.
Chen, S. S., & Huang, C. W. (2010). Long-run equilibrium and short-run dynamics in energy stock prices and oil prices. Energy Economics, 32(1), 19–26.
Corbet, S., Meegan, A., Larkin, C., Lucey, B., & Yarovaya, L. (2018). Exploring the dynamic relationships between cryptocurrencies and other financial assets. Economics Letters, 165, 28–34.
Engle, R. F., & Granger, C. W. J. (1987). Co-integration and error correction: Representation, estimation, and testing. Econometrica, 55(2), 251–276.
Tsay, R. S. (2010). Analysis of financial time series (3rd ed.). Wiley.
What this tool does is bring that theory into practice. It estimates a long-run equilibrium between two assets (Y ~ α + βX), calculates the residual spread (ε), and then evaluates whether that spread behaves in a mean-reverting way. The Z-Score tells you when the spread has moved far from its historical mean. The Error Correction Model (ECM) adds a second layer: it checks whether the spread tends to close again, and how strong that adjustment pressure is. If λ is negative and stable, the relationship is cointegrated and mean-reverting. If not, the pair is unstable — even if the Z-Score looks attractive.
Signals are summarized clearly:
– Strong Setup appears when we see both extreme divergence and a stable, negative λ.
– Weak Setup means only partial confirmation.
– Invalid means the relationship is breaking down.
Why this matters
Cointegration analysis is widely used by institutional desks, especially in pairs trading, statistical arbitrage, and risk management. Classic cases include equity index futures vs ETFs (Alexander, 2001), oil vs energy stocks (Chen & Huang, 2010), or swap spreads in fixed income (Tsay, 2010). In crypto, temporary cointegration has been observed between BTC and ETH in periods of high liquidity (Corbet et al., 2018). With this indicator, you can explore these relationships directly on TradingView, test asset pairs, and see when divergences become statistically significant.
Limitations to keep in mind
– Timeframe choice matters: Daily calculations are usually more stable; weekly or intraday often show unstable signals. To avoid confusion, you can fix the calculation timeframe in the settings.
– Cointegration is not permanent. Structural breaks (earnings, regulation, macro shifts) can destroy old relationships.
– Results are approximate. Rolling regressions, Z-Scores, and ECM estimates are sensitive to the length of the chosen windows.
– This is a research tool — not a ready-made trading system. It should be used as one piece in a broader framework.
References
Alexander, C. (2001). Market models: A guide to financial data analysis. Wiley.
Chen, S. S., & Huang, C. W. (2010). Long-run equilibrium and short-run dynamics in energy stock prices and oil prices. Energy Economics, 32(1), 19–26.
Corbet, S., Meegan, A., Larkin, C., Lucey, B., & Yarovaya, L. (2018). Exploring the dynamic relationships between cryptocurrencies and other financial assets. Economics Letters, 165, 28–34.
Engle, R. F., & Granger, C. W. J. (1987). Co-integration and error correction: Representation, estimation, and testing. Econometrica, 55(2), 251–276.
Tsay, R. S. (2010). Analysis of financial time series (3rd ed.). Wiley.
보호된 스크립트입니다
이 스크립트는 비공개 소스로 게시됩니다. 하지만 제한 없이 자유롭게 사용할 수 있습니다 — 여기에서 자세히 알아보기.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
보호된 스크립트입니다
이 스크립트는 비공개 소스로 게시됩니다. 하지만 제한 없이 자유롭게 사용할 수 있습니다 — 여기에서 자세히 알아보기.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.