OPEN-SOURCE SCRIPT
Telah dikemas kini rj_temu_pair_trade

a simple "temu" implementation of a pair trade
see https://robotjames.substack.com/ for details.
see https://robotjames.substack.com/ for details.
Nota Keluaran
A non-compounding, fixed-notional Bollinger-Band reversion strategy designed for pair trading. Includes MA-based exits, optional stop-loss + time-stop, synthetic Sharpe calculation, and on-chart performance table. Configured to align with TradingView’s Strategy Tester metrics.Overview
This strategy implements a fixed-notional, non-compounding Bollinger-Band reversion system suitable for pair trading. It is designed to operate on ratio charts (e.g., PLD/REXR) or any spread expression the user applies.
Trades are entered on the next bar following a band-cross signal, and exits can be triggered by a moving-average cross, an optional time-stop, or an optional stop-loss.
The strategy sizes each trade with a constant notional amount (e.g., $100,000), ensuring stable performance reporting across long histories and preventing unintended compounding.
Features
Entry Conditions
- Long entry when price crosses below the lower Bollinger Band.
- Short entry when price crosses above the upper Bollinger Band.
- Optional “close-only” mode to require the close to cross the bands.
Exit Conditions
- Moving-average cross exit.
- Optional time-stop (e.g., exit after 5 bars).
- Optional stop-loss based on percentage move relative to entry.
Trade Sizing
- Uses strategy.cash with fixed notional sizing per trade.
- Prevents compounding so results remain stable and comparable across instruments.
On-Chart Performance Summary
- Total PnL (%) based on strategy.netprofit.
- Average PnL per trade (%).
- Win rate.
- Annualised Sharpe ratio computed from synthetic daily returns.
- All statistics are aligned with TradingView’s Strategy Tester.
Visual Markers
- Entry/exit markers (L, S, C, TS, SL).
- Optional pre-cost PnL labels at closing bars.
Alert Triggers
- Open Long
- Open Short
- Close Long
- Close Short
These enable users to run the strategy on multiple symbols or pair charts and receive real-time entry/exit signals.
Intended Use
This script is provided for educational purposes and workflow automation.
It is not a trade signal service and makes no performance guarantees.
It is suitable for:
- Pair-trading / spread-trading setups
- Ratio charts (A/B) or synthetic spreads
- Testing fixed-notional mean-reversion systems
- Creating alerts for live monitoring or manual execution workflows
Disclaimer
This script is for educational purposes only and is not financial advice.
Trading involves risk, including possible loss of capital.
Past performance does not guarantee future results.
Users are responsible for verifying accuracy and suitability for their own circumstances.
Nota Keluaran
v.1.1.1 - alerts on trade signalsSkrip 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.