OPEN-SOURCE SCRIPT

Marcius Studio® - Cross-Asset Correlator™

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

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 FARTCOINUSDT.P / PENGUUSDT.P

  • Timeframe: 1H
  • SMA Period: 60
  • Correlation Period: 25
  • Upper Threshold: 0.9
  • Lower Threshold: 0.1
  • percentage_investment: 10%


How the Code Works
  1. Retrieves closing prices of two selected assets.
  2. Calculates correlation coefficient and moving averages.
  3. When correlation breaks below the lower threshold, the script opens a pair trade (long/short depending on SMA relation).
  4. When correlation recovers above the upper threshold, all open trades are closed.
  5. Real-time alerts are generated in JSON format for OKX bots (ENTER/EXIT signals).
  6. Built-in backtesting engine tracks PnL, trades, and statistics (7d / 30d / total).
  7. 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.

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.