OPEN-SOURCE SCRIPT
Telah dikemas kini rj's temu perp pair trade

Overview
rj’s temu perp pair trade is a simple, robust pairs-trading strategy designed for crypto perpetual futures, implemented directly on ratio charts (A / B) in TradingView.
The strategy trades mean reversion in relative price using Bollinger Bands, while keeping sizing, execution logic, and diagnostics intentionally simple and transparent.
This script is designed primarily for signal research and pair selection, not for fully accurate two-leg PnL simulation inside TradingView.
Strategy Concept
The strategy operates on a ratio chart:
Asset A / Asset B
The ratio represents relative performance between two assets.
Core idea
When the ratio deviates significantly from its recent mean, it tends to revert. (if you pick stuff that has very similar drivers and little insider trading flows.
Bollinger Bands provide a simple, robust way to define “too far”.
Entry Logic
Using Bollinger Bands on the ratio price:
Long ratio
Short ratio
Entries are generated on bar close, with fills occurring on the next bar open (TradingView’s internal behavior).
Exit Logic
Positions are closed when any of the following occurs:
Ratio crosses back through the Bollinger midline
Position held longer than maxBarsInTrade (optional)
Fixed % stop based on ratio price (optional)
Each exit is explicitly labeled on the chart:
Position sizing and margin
Mating requirements are set to 1% for long/short to disable margin rejections for research purposes.
What TradingView PnL means (important)
When trading ratio charts, TradingView treats the ratio as a single synthetic instrument.
This script intentionally does not attempt to convert PnL into USDT inside TradingView.
Instead:
Summary Table
The on-chart summary table reports Strategy Tester-aligned metrics only:
These metrics are internally consistent but should be treated as indicative, not execution-accurate.
Recommended workflow
Inside TradingView
Outside TradingView
Use exported trade data to:
Limitations
This script does not:
It is not a trading system. It is a clean, robust research and signal-generation tool.
rj’s temu perp pair trade is a simple, robust pairs-trading strategy designed for crypto perpetual futures, implemented directly on ratio charts (A / B) in TradingView.
The strategy trades mean reversion in relative price using Bollinger Bands, while keeping sizing, execution logic, and diagnostics intentionally simple and transparent.
This script is designed primarily for signal research and pair selection, not for fully accurate two-leg PnL simulation inside TradingView.
Strategy Concept
The strategy operates on a ratio chart:
Asset A / Asset B
The ratio represents relative performance between two assets.
Core idea
When the ratio deviates significantly from its recent mean, it tends to revert. (if you pick stuff that has very similar drivers and little insider trading flows.
Bollinger Bands provide a simple, robust way to define “too far”.
Entry Logic
Using Bollinger Bands on the ratio price:
Long ratio
- Ratio crosses below the lower band
- Interpreted as A cheap vs B
Short ratio
- Ratio crosses above the upper band
- Interpreted as A expensive vs B
Entries are generated on bar close, with fills occurring on the next bar open (TradingView’s internal behavior).
Exit Logic
Positions are closed when any of the following occurs:
Ratio crosses back through the Bollinger midline
Position held longer than maxBarsInTrade (optional)
Fixed % stop based on ratio price (optional)
Each exit is explicitly labeled on the chart:
- C → mean reversion
- TS → time stop
- SL → stop loss
Position sizing and margin
- Positions are sized as a percentage of Strategy Tester equity
- Default: 10% of equity per trade
- This ensures consistent risk within TradingView, even on ratio charts
Mating requirements are set to 1% for long/short to disable margin rejections for research purposes.
What TradingView PnL means (important)
When trading ratio charts, TradingView treats the ratio as a single synthetic instrument.
- PnL is reported in the denominator (quote) unit e.g. on UNI / SUSHI, PnL is in SUSHI
- Strategy Tester does not simulate two legs
- Absolute PnL, Sharpe, and drawdowns are not USDT-accurate
This script intentionally does not attempt to convert PnL into USDT inside TradingView.
Instead:
- TradingView is used for signal behavior, regime analysis, and pair comparison
- Accurate two-leg USDT PnL should be computed externally
Summary Table
The on-chart summary table reports Strategy Tester-aligned metrics only:
- Total PnL (%)
- Number of closed trades
- Win rate
- Average PnL per trade
- Sharpe ratio (annualized, based on Strategy Tester equity)
- PnL units (syminfo.currency)
These metrics are internally consistent but should be treated as indicative, not execution-accurate.
Recommended workflow
Inside TradingView
- Use this script to:
- Explore pair behavior
- Validate mean-reversion dynamics
- Study regime dependence
- Compare relative signal quality across pairs
Outside TradingView
Use exported trade data to:
- Aggregate daily PnL
- Normalize by initial capital
- Apply portfolio weights
- Vol-target and analyze drawdowns
- Add funding, fees, and execution logic
Limitations
This script does not:
- Simulate two-leg execution
- Account for funding rates
- Model fees or slippage per leg
- Provide USDT-accurate PnL
It is not a trading system. It is a clean, robust research and signal-generation tool.
Nota Keluaran
added alertsSkrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.