OPEN-SOURCE SCRIPT
Marcius Studio® - Cross-Asset Correlator™

Cross-Asset Correlator™ — a pair-trading strategy that identifies correlation breakdowns between two assets and captures profit opportunities from market inefficiencies.
The strategy enters trades when the correlation drops below a set threshold and closes positions once correlation recovers.
The main concept is to exploit temporary divergence between two assets by going long the stronger one and short the weaker one, aiming to profit when their correlation reverts.
TradingView Limitation
By default, TradingView’s built-in Strategy interface does not support backtesting with two different assets.
To overcome this, the script is implemented as an indicator with a fully custom backtesting engine that calculates PnL, trades, and performance statistics directly on the chart.
Idea
Markets move in clusters: altcoins follow BTC, memecoins track Solana, L2 projects mirror Ethereum. But correlations aren’t perfect—temporary divergences create pricing inefficiencies.
The logic:
The market eventually corrects, but the inefficiency window allows profit before realignment.
OKX Signal Bot Integration
This script includes a built-in interface for OKX Signal Bot.
It can generate structured JSON alerts (ENTER / EXIT, long / short) and directly manage trades on OKX exchange.
This allows seamless automation of correlation-based strategies without manual order execution.
Strategy Parameters
Example Settings
FARTCOINUSDT.P / 
PENGUUSDT.P
How the Code Works
Disclaimer
Trading involves risk — always do your own research (DYOR) and seek professional financial advice. We are not responsible for any potential financial losses.
The strategy enters trades when the correlation drops below a set threshold and closes positions once correlation recovers.
The main concept is to exploit temporary divergence between two assets by going long the stronger one and short the weaker one, aiming to profit when their correlation reverts.
Important: This script illustrates asset correlation concepts for educational purposes only. It's not for live trading—requires adjustments and offers no performance guarantees. Always apply risk management.
TradingView Limitation
By default, TradingView’s built-in Strategy interface does not support backtesting with two different assets.
To overcome this, the script is implemented as an indicator with a fully custom backtesting engine that calculates PnL, trades, and performance statistics directly on the chart.
Idea
Markets move in clusters: altcoins follow BTC, memecoins track Solana, L2 projects mirror Ethereum. But correlations aren’t perfect—temporary divergences create pricing inefficiencies.
The logic:
- When an asset lags or overshoots its usual correlation, it’s a mispricing opportunity.
- Trade the reversion: buy undervalued divergence, sell overextended convergence.
The market eventually corrects, but the inefficiency window allows profit before realignment.
OKX Signal Bot Integration
This script includes a built-in interface for OKX Signal Bot.
It can generate structured JSON alerts (ENTER / EXIT, long / short) and directly manage trades on OKX exchange.
This allows seamless automation of correlation-based strategies without manual order execution.
Note: The OKX Signal Bot (for demo use only) assists with alerts & trade management but does not ensure profits. You are fully responsible for your trades—always apply risk management.
Strategy Parameters
- Symbol 1 / Symbol 2: trading instruments to be analyzed.
- SMA Period: smoothing period for price averages.
- Correlation Period: number of bars used to calculate correlation coefficient.
- Upper Correlation Threshold: level above which trades are closed.
- Lower Correlation Threshold: level below which new trades are opened.
- percentage_investment (%): allocation per entry signal (used for OKX integration).
Example Settings
- Timeframe: 1H
- SMA Period: 60
- Correlation Period: 25
- Upper Threshold: 0.9
- Lower Threshold: 0.1
- percentage_investment: 10%
How the Code Works
- Retrieves closing prices of two selected assets.
- Calculates correlation coefficient and moving averages.
- When correlation breaks below the lower threshold, the script opens a pair trade (long/short depending on SMA relation).
- When correlation recovers above the upper threshold, all open trades are closed.
- Real-time alerts are generated in JSON format for OKX bots (ENTER/EXIT signals).
- Built-in backtesting engine tracks PnL, trades, and statistics (7d / 30d / total).
- Visual labels mark entries, exits, and PnL results directly on the chart.
Disclaimer
Trading involves risk — always do your own research (DYOR) and seek professional financial advice. We are not responsible for any potential financial losses.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
Need a custom TradingView bot, indicator, strategy? We'll develop a solution tailored to your needs. Build your idea at studio.marcius.com
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
Need a custom TradingView bot, indicator, strategy? We'll develop a solution tailored to your needs. Build your idea at studio.marcius.com
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。