Sector Divergence DashboardStatistical arbitrage dashboard for markets and sector ETFs
This Sector Divergence Dashboard is a tool designed to identify mean-reversion opportunities across U.S. equity sectors. I've built it to help me with portfolio management and sector allocation by identifying uncorrelated sectors and divergences between indices and sector ETFs. These divergences are often good investment opportunities.
The indicator also helps you with sector rotation by identifying when sectors have diverged too far from their historical relationships with the broader market. This is a similar methodology used daily in institutional portfolio management and hedge funds.
In this dashboard, you can see:
Z-Score Analysis on log price ratios to detect statistical anomalies
Dual-timeframe correlation tracking to identify relationship breakdowns
Composite scoring that combines divergence magnitude, correlation shifts, and momentum
Correlation heatmap for instant relationship assessment across all pairs
You see exactly which pairs are statistically mispriced and likely to revert to their historical mean.
NOTE: This dashboard is computationally heavy and might take up to one minute to load in your TradingView.
The Mathematics
1. Price Ratio Z-Score
The indicator calculates the logarithmic price ratio between two assets (e.g., SPY/XLE) and measures how many standard deviations this ratio has moved from its historical average. A z-score of +2.0 means the pair is 2 standard deviations expensive relative to history. This can be a mean-reversion setup.
2. Correlation Breakdown Detection
Short-term correlation (35 bars) is compared against long-term correlation (100 bars). You can change these parameters BTW. When correlations diverge significantly, it signals that the normal relationship has temporarily broken, potentially creating trading opportunities.
3. Relative Performance
Measures the momentum difference between pairs over 300 bars (roughly 60 weeks on daily charts). This captures longer-term structural shifts versus short-term noise.
4. Composite Score
All three metrics are normalized and weighted to create a single ranking score:
50% Z-Score Weight - Primary driver of mean reversion probability
25% Correlation Breakdown - Relationship stability metric
25% Relative Performance - Momentum/trend context
Features
1. Correlation Heatmap
Visualize all pairwise correlations
Color-coded from red (negative correlation) to green (strong positive)
Spot which sectors are moving together or decoupling
2. Divergence Rankings Table
Top 15 SPY-vs-sector pairs ranked by composite opportunity score
Z-scores, correlations, performance differentials, and signals
Color-coded from gray (neutral) to red (extreme divergence)
Scan it daily for setups
3. Deep Dive Chart
Detailed z-score visualization for any selected pair
Visual zones showing normal range, signal threshold, and strong signal areas
Short-term and long-term correlation overlays
Real-time information label with current metrics and signal status
Perfect for analyzing specific opportunities in depth
You can define which symbols you want to deep dive in the parameters
Parameter Guide
Short-Term Correlation - Recent relationship strength
Long-Term Correlation - Historical baseline relationship
Z-Score Length - Mean reversion lookback period
Relative Performance - Longer-term momentum context
Pro Tip : Increase z-score length to 150+ for fewer but stronger signals. Decrease to 50-75 for more frequent opportunities (but more noisy).
Use Cases
Sector Rotation: Identify which sectors are over/undervalued relative to the market
Portfolio Rebalancing: Data-driven signals for tactical asset allocation adjustments
Pairs Trading: Statistical arbitrage between correlated instruments
Risk Management: Monitor correlation stability across your portfolio
Market Regime Detection: Spot when sector relationships are breaking down
Swing Trading: Mean-reversion setups with clear entry/exit rules
Example:
XLK, a key tech ETF, is typically very correlated with the S&P 500 with a 0.88 correlation. Our dashboard detected a divergence between both, which signals a buy/rotation to XLK.
Let me know if you have any requests, improvements suggestions or feedback :)
Penunjuk Pine Script®













