OPEN-SOURCE SCRIPT
Rolling Correlation & Breakdown Detector [LuxAlgo]

The Rolling Correlation & Breakdown Detector indicator is a specialized "trust meter" designed for statistical arbitrage and pairs trading that monitors the stability of the relationship between two assets to identify when mean-reversion strategies are likely to fail.
🔶 USAGE
This indicator functions as a decision filter rather than a standalone entry signal generator. It is intended to be used alongside spread indicators or Z-score models to determine if the underlying relationship between two assets is healthy enough to trade.
The script monitors two primary factors: the raw Pearson correlation and the stability of that correlation. This helps traders avoid the "divergence trap," where a price gap looks like a mean-reversion opportunity, but the assets have actually undergone a structural regime shift.
🔹 The Three-State System
The indicator categorizes the relationship into three distinct regimes:
🔹 Statistical Arbitrage Filtering
🔶 DETAILS
While most traders only look at the absolute correlation value, this indicator introduces the concept of Correlation Stability. A pair with a lower but stable correlation is often more tradable than a pair with high correlation that is rapidly collapsing.
The script calculates the standard deviation of the correlation over a "Stability Window." If the correlation fluctuates wildly, the stability metric will spike, triggering a Warning or Breakdown state even if the raw correlation value remains relatively high. This acts as a "circuit breaker" to protect traders from macro-driven divergences or structural news events.
🔶 SETTINGS
🔹 General Settings
🔹 Breakdown Detection Thresholds
🔹 Dashboard
* Dashboard: Toggles the visibility of the real-time information table.
* Position/Size: Customizes the location and scale of the on-screen dashboard.
🔶 USAGE
This indicator functions as a decision filter rather than a standalone entry signal generator. It is intended to be used alongside spread indicators or Z-score models to determine if the underlying relationship between two assets is healthy enough to trade.
The script monitors two primary factors: the raw Pearson correlation and the stability of that correlation. This helps traders avoid the "divergence trap," where a price gap looks like a mean-reversion opportunity, but the assets have actually undergone a structural regime shift.
🔹 The Three-State System
The indicator categorizes the relationship into three distinct regimes:
- Healthy (Green): The correlation is high and stable. This is the optimal environment for statistical arbitrage trades.
- Warning (Orange): The correlation is weakening or becoming volatile. New trades should be approached with caution, and existing positions should be managed tightly.
- Breakdown (Red): The assets have "divorced." The correlation has collapsed or is moving erratically. In this state, mean-reversion signals should be ignored as the assets are no longer moving in tandem.
🔹 Statistical Arbitrage Filtering
- Valid Trade: Your spread indicator shows an extreme (e.g., Z-Score > 2) AND the detector is Green.
- Invalid Trade: Your spread indicator shows an extreme, but the detector is Red. This suggests a "regime shift" where one asset is repricing independently of the other.
🔶 DETAILS
While most traders only look at the absolute correlation value, this indicator introduces the concept of Correlation Stability. A pair with a lower but stable correlation is often more tradable than a pair with high correlation that is rapidly collapsing.
The script calculates the standard deviation of the correlation over a "Stability Window." If the correlation fluctuates wildly, the stability metric will spike, triggering a Warning or Breakdown state even if the raw correlation value remains relatively high. This acts as a "circuit breaker" to protect traders from macro-driven divergences or structural news events.
🔶 SETTINGS
🔹 General Settings
- Asset B: The secondary symbol you wish to compare against the current chart symbol.
- Correlation Length: The rolling lookback window used for the Pearson correlation calculation.
- Stability Window: The window used to measure the volatility (standard deviation) of the correlation.
🔹 Breakdown Detection Thresholds
- Healthy Threshold: The minimum correlation value required to be considered in a "Healthy" state.
- Breakdown Threshold: The level below which the relationship is considered "Broken."
- Stability Threshold: The maximum allowed volatility in the correlation before the state shifts to a Warning or Breakdown.
🔹 Dashboard
* Dashboard: Toggles the visibility of the real-time information table.
* Position/Size: Customizes the location and scale of the on-screen dashboard.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.