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.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
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.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
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.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.