OPEN-SOURCE SCRIPT
ที่อัปเดต:

rj's temu perp pair trade

103
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
  • 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.
เอกสารเผยแพร่
added alerts

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน