OPEN-SOURCE SCRIPT

Correlation & Mean Reversion - Paired Stocks/ETFs Trading

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

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.