INVITE-ONLY SCRIPT
Güncellendi

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

43
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.

| 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.
Sürüm Notları
Previous method used to calculate Mean Reversion % probability method did not represent the usual probability of reverting to the mean. Instead, it represented the probability of a move being in the tail beyond |z|.

Updated calculation method now shows probability of mean reversion (the closer to zero, the more likely to revert) using two-sided p-value (twice the tail area).
Sürüm Notları
Previous method used to calculate Mean Reversion % probability method did not represent the usual probability of reverting to the mean. Instead, it represented the probability of a move being in the tail beyond |z|.

Updated calculation method now shows probability of mean reversion (0-100 %) using two-sided p-value (twice the tail area).

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.