INVITE-ONLY SCRIPT
Correlation & Mean Reversion - Paired Stocks/ETFs (By MC)

This indicator is designed to help identify mean reversion opportunities between two correlated instruments, such as ETFs or stocks (e.g., SPY vs. TLT). It provides statistical insight, visual signals, and a summary table to support pair trading strategies.
🔍 Key Functions:
Price Ratio Analysis
Calculates and monitors the price ratio (A/B) between two user-defined tickers over a rolling period.
Z-Score Calculation
Measures how far the current ratio deviates from its mean in standard deviation units (Z-score), with safeguards against unstable values.
Mean Reversion Probability
Uses a normal distribution function to estimate the likelihood of the ratio reverting to its mean — shown as a percentage.
Rolling Correlation
Computes the correlation of log returns between the two instruments to gauge relationship strength.
Trade Signal Alerts
🔴 Strong Mean Reversion if probability > 95%
🟡 Moderate Mean Reversion if probability > 80%
Color-Coded Backgrounds & Signal Markers
Visual indicators appear on the chart to flag potential trade setups.
Stats Table (Mobile-Optimized)
Displays:
🎯 Use Case:
This tool is ideal for pair traders looking to exploit statistical arbitrage opportunities by entering trades when price relationships deviate from their historical norm.
🔍 Key Functions:
Price Ratio Analysis
Calculates and monitors the price ratio (A/B) between two user-defined tickers over a rolling period.
Z-Score Calculation
Measures how far the current ratio deviates from its mean in standard deviation units (Z-score), with safeguards against unstable values.
Mean Reversion Probability
Uses a normal distribution function to estimate the likelihood of the ratio reverting to its mean — shown as a percentage.
Rolling Correlation
Computes the correlation of log returns between the two instruments to gauge relationship strength.
| Correlation Value | Interpretation |
| ----------------- | ----------------------------- |
| +1.0 | Perfect positive correlation (price of both move in the same direction)|
| +0.7 to +0.9 | Strong positive correlation |
| +0.4 to +0.6 | Moderate positive correlation |
| 0 | No correlation (independent) |
| -0.4 to -0.6 | Moderate negative correlation |
| -0.7 to -0.9 | Strong negative correlation |
| -1.0 | Perfect negative correlation (price both move in the opposite direction)|
Trade Signal Alerts
🔴 Strong Mean Reversion if probability > 95%
🟡 Moderate Mean Reversion if probability > 80%
- % Reversion >= 0.9 - "High"
- % Reversion >= 0.8 - "Moderate High"
- % Reversion >= 0.6 - "Low"
- % Reversion < 0.6 "Very Low"
Color-Coded Backgrounds & Signal Markers
Visual indicators appear on the chart to flag potential trade setups.
Stats Table (Mobile-Optimized)
Displays:
Symbol A & B
Ratio
Z-Score
Mean Reversion %
Rolling Correlation
Trade Quality: High, Moderate High, Low, or Very Low (color-coded)
User Customization
Table position (top/bottom left/right)
Toggle display of plots (Z-score, correlation, ratio overlay)
Chart style for mean reversion % (line/histogram)
🎯 Use Case:
This tool is ideal for pair traders looking to exploit statistical arbitrage opportunities by entering trades when price relationships deviate from their historical norm.
僅限邀請腳本
只有經作者授權的使用者才能訪問此腳本,且通常需付費。您可以將此腳本加入收藏,但需先向作者申請並獲得許可後才能使用 — 點擊此處了解更多。如需更多詳情,請依照作者說明或直接聯繫mclee1.2006。
除非您完全信任其作者並了解腳本的工作原理,否則TradingView不建議您付費或使用腳本。您也可以在我們的社群腳本中找到免費的開源替代方案。
作者的說明
PM me for access
提醒:在請求訪問權限之前,請閱讀僅限邀請腳本指南。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
僅限邀請腳本
只有經作者授權的使用者才能訪問此腳本,且通常需付費。您可以將此腳本加入收藏,但需先向作者申請並獲得許可後才能使用 — 點擊此處了解更多。如需更多詳情,請依照作者說明或直接聯繫mclee1.2006。
除非您完全信任其作者並了解腳本的工作原理,否則TradingView不建議您付費或使用腳本。您也可以在我們的社群腳本中找到免費的開源替代方案。
作者的說明
PM me for access
提醒:在請求訪問權限之前,請閱讀僅限邀請腳本指南。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。