OPEN-SOURCE SCRIPT
Spearman Correlation

🔗 Spearman Correlation – Ranked Relationship Tracker
Overview:
This indicator calculates and plots the Spearman Rank Correlation Coefficient between the current chart’s asset and a custom comparison ticker (the example shown is BTC vs the OTHERS market cap for crypto). Unlike Pearson correlation, which measures linear relationships, Spearman correlation captures monotonic (ranked) relationships—making it better suited for analysing assets that move in sync but not necessarily in a linear fashion.
🧠 What It Does:
Computes ranked correlation between two assets over a user-defined lookback period
Smooths the correlation curve for better readability
Visually shades the background by correlation strength and direction:
🟩 Strong Positive (+0.5 to +1)
🟨 Weak Positive (+0.1 to +0.5)
⬜ No Correlation (–0.1 to +0.1)
🟧 Weak Negative (–0.5 to –0.1)
🟥 Strong Negative (–1 to –0.5)
⚙️ User Inputs:
Lookback Period: Number of bars used to calculate correlation
Comparison Ticker: Choose any asset to compare against
Shading Toggles: Customize which correlation zones are highlighted
📈 Use Cases:
Identify evolving relationships between assets (e.g., BTC vs DXY, ETH vs SPX)
Spot when assets become inversely correlated or lose correlation entirely
Track regime shifts where traditional relationships break down or re-align
Use alongside trend or momentum strategies to add a cross-asset confirmation layer
🔍 Interpreting the Correlation:
+1 → Perfect positive (ranks match exactly)
+0.5 to +1 → Strong positive relationship
+0.1 to +0.5 → Weak but positive relationship
–0.1 to +0.1 → Essentially uncorrelated
–0.5 to –0.1 → Weak negative correlation
–1 to –0.5 → Strong inverse relationship
–1 → Perfect negative (rankings are completely opposite)
🧪 Technical Notes:
Calculation uses ranked returns to better reflect monotonic relationships
Smoothed with a simple moving average (SMA) for stability
Arrays are managed internally to maintain performance and adaptability
This script is ideal for traders seeking deeper insight into cross-asset dynamics, portfolio hedging, or timing divergence-based strategies.
Overview:
This indicator calculates and plots the Spearman Rank Correlation Coefficient between the current chart’s asset and a custom comparison ticker (the example shown is BTC vs the OTHERS market cap for crypto). Unlike Pearson correlation, which measures linear relationships, Spearman correlation captures monotonic (ranked) relationships—making it better suited for analysing assets that move in sync but not necessarily in a linear fashion.
🧠 What It Does:
Computes ranked correlation between two assets over a user-defined lookback period
Smooths the correlation curve for better readability
Visually shades the background by correlation strength and direction:
🟩 Strong Positive (+0.5 to +1)
🟨 Weak Positive (+0.1 to +0.5)
⬜ No Correlation (–0.1 to +0.1)
🟧 Weak Negative (–0.5 to –0.1)
🟥 Strong Negative (–1 to –0.5)
⚙️ User Inputs:
Lookback Period: Number of bars used to calculate correlation
Comparison Ticker: Choose any asset to compare against
Shading Toggles: Customize which correlation zones are highlighted
📈 Use Cases:
Identify evolving relationships between assets (e.g., BTC vs DXY, ETH vs SPX)
Spot when assets become inversely correlated or lose correlation entirely
Track regime shifts where traditional relationships break down or re-align
Use alongside trend or momentum strategies to add a cross-asset confirmation layer
🔍 Interpreting the Correlation:
+1 → Perfect positive (ranks match exactly)
+0.5 to +1 → Strong positive relationship
+0.1 to +0.5 → Weak but positive relationship
–0.1 to +0.1 → Essentially uncorrelated
–0.5 to –0.1 → Weak negative correlation
–1 to –0.5 → Strong inverse relationship
–1 → Perfect negative (rankings are completely opposite)
🧪 Technical Notes:
Calculation uses ranked returns to better reflect monotonic relationships
Smoothed with a simple moving average (SMA) for stability
Arrays are managed internally to maintain performance and adaptability
This script is ideal for traders seeking deeper insight into cross-asset dynamics, portfolio hedging, or timing divergence-based strategies.
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.
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.
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.