OPEN-SOURCE SCRIPT

Correlation & Mean Reversion - Paired Stocks/ETFs Trading

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

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.