OPEN-SOURCE SCRIPT
Pair Trading

PAIR TRADING
Description:
This indicator is a simple and intuitive tool for rotating between two assets based on their relative price ratio. By comparing the prices of Asset A and Asset B, it plots a “ratio line” (gray) with dynamic upper and lower boundaries (red and blue).
When the ratio reaches the red line, Asset A is expensive → rotate out of A and into B.
When the ratio touches the blue line, Asset A is cheap → rotate back into A.
The chart also shows:
🔹 Background highlights for visual cues
🔹 “Rotate to A” or “Rotate to B” markers for easy decisions
🔹 A live summary table with mean ratio, upper/lower boundaries, and current ratio
How to Use:
Select Asset A and Asset B in the settings.
Adjust the Lookback Period and Threshold if needed.
Watch the gray ratio line as it moves:
Above red line? → Consider rotating into B
Below blue line? → Consider rotating into A
Use the background color changes and rotation labels to spot clear rotation opportunities!
Why Pair Trading?
Pair trading is a powerful way to manage a portfolio because it neutralizes market direction risk and focuses on relative value.
By rotating between correlated assets, you can:
Smooth out returns
Avoid holding a weak asset too long
Capture reversion when assets diverge too far
This approach can enhance risk-adjusted returns and help keep your portfolio balanced and nimble!
How to Pick Pairs:
Choose assets with strong correlation or similar drivers.
Look for common trends (sector, macro).
Start with assets you know best (high-conviction ideas).
Make sure both have good liquidity for reliable trading!
TO HELP FIND CORRELATED ASSETS:
Use the Correlation Coefficient indicator in TradingView:
Click Indicators
Search for “Correlation Coefficient”
Add it to your chart
Input the symbol of the second asset (e.g., if you’re on MSTR, input TSLA).
This plots the rolling correlation coefficient — super helpful!
Pair trading can turn big swings into steady rotations and help you stay active even when the market is choppy. It’s a simple, practical approach to keep your portfolio balanced.
Description:
This indicator is a simple and intuitive tool for rotating between two assets based on their relative price ratio. By comparing the prices of Asset A and Asset B, it plots a “ratio line” (gray) with dynamic upper and lower boundaries (red and blue).
When the ratio reaches the red line, Asset A is expensive → rotate out of A and into B.
When the ratio touches the blue line, Asset A is cheap → rotate back into A.
The chart also shows:
🔹 Background highlights for visual cues
🔹 “Rotate to A” or “Rotate to B” markers for easy decisions
🔹 A live summary table with mean ratio, upper/lower boundaries, and current ratio
How to Use:
Select Asset A and Asset B in the settings.
Adjust the Lookback Period and Threshold if needed.
Watch the gray ratio line as it moves:
Above red line? → Consider rotating into B
Below blue line? → Consider rotating into A
Use the background color changes and rotation labels to spot clear rotation opportunities!
Why Pair Trading?
Pair trading is a powerful way to manage a portfolio because it neutralizes market direction risk and focuses on relative value.
By rotating between correlated assets, you can:
Smooth out returns
Avoid holding a weak asset too long
Capture reversion when assets diverge too far
This approach can enhance risk-adjusted returns and help keep your portfolio balanced and nimble!
How to Pick Pairs:
Choose assets with strong correlation or similar drivers.
Look for common trends (sector, macro).
Start with assets you know best (high-conviction ideas).
Make sure both have good liquidity for reliable trading!
TO HELP FIND CORRELATED ASSETS:
Use the Correlation Coefficient indicator in TradingView:
Click Indicators
Search for “Correlation Coefficient”
Add it to your chart
Input the symbol of the second asset (e.g., if you’re on MSTR, input TSLA).
This plots the rolling correlation coefficient — super helpful!
Pair trading can turn big swings into steady rotations and help you stay active even when the market is choppy. It’s a simple, practical approach to keep your portfolio balanced.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.