OPEN-SOURCE SCRIPT

Rolling Correlation & Breakdown Detector [LuxAlgo]

2 413
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:
  • 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.

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。