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が提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。