OPEN-SOURCE SCRIPT
Correlation & Mean Reversion - Paired Stocks/ETFs Trading

This indicator is designed to analyze pair trading opportunities between two assets by evaluating:
🔧 Core Features
1. Symbol Pair Analysis
Takes two input symbols (Symbol A, Symbol B).
Calculates the price ratio (A/B) and compares it to a user-defined targetRatio.
2. Z-Score of Ratio
Computes Z-Score of the ratio over a user-defined lookback window to measure how far the ratio deviates from its mean.
This gauges whether the ratio is likely to revert to the mean.
3. Reversion Probability
Applies a normal CDF approximation to Z-Score to estimate the probability of mean reversion.
Flags moderate (80%+) and strong (95%+) reversion signals.
4. Correlation
Calculates the rolling correlation of log returns between Symbol A and Symbol B.
Useful to confirm if the assets historically move together.
🔧 Core Features
1. Symbol Pair Analysis
Takes two input symbols (Symbol A, Symbol B).
Calculates the price ratio (A/B) and compares it to a user-defined targetRatio.
2. Z-Score of Ratio
Computes Z-Score of the ratio over a user-defined lookback window to measure how far the ratio deviates from its mean.
This gauges whether the ratio is likely to revert to the mean.
3. Reversion Probability
Applies a normal CDF approximation to Z-Score to estimate the probability of mean reversion.
Flags moderate (80%+) and strong (95%+) reversion signals.
4. Correlation
Calculates the rolling correlation of log returns between Symbol A and Symbol B.
Useful to confirm if the assets historically move together.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
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.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
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.