OPEN-SOURCE SCRIPT

CTA-min D1 — Donchian 55/20 Trend Breakout (ATR Risk)

192
What it is
A clean, daily trend-following breakout inspired by classic CTA/Turtle logic. It buys strength and sells weakness, then lets winners run with a channel-based trailing stop. No curve-fitting, no clutter—just rules.

How it trades

Timeframe: Daily (D1)

Entry: Close breaks the previous 55-bar Donchian channel (above for longs, below for shorts).

Exit/Trail: Trailing stop at the 20-bar Donchian channel on the opposite side (no fixed TP).

Risk: Initial stop = ATR(N) × stopMult (ATR is smoothed). Position size risks riskPct% of equity based on stop distance.

Labels: “BUY/SELL” only on the entry bar; “STOP BUY/STOP SELL” only on the exit bar.

Pyramiding: Off (one position at a time).

Regime Alignment with EMAs (recommended filter, not enforced by code)

Add EMA 50 and EMA 200 to the D1 chart.

Long bias: take BUY signals only when EMA50 > EMA200 (bullish regime).

Short bias: take SELL signals only when EMA50 < EMA200 (bearish regime).

Optional: for extra selectivity, require the H4 EMAs (50/200) to align with D1 before acting on a signal.

Inputs
entryN (55), exitN (20), atrLen (20), atrSmooth (10), stopMult (2.0), riskPct (0.5%–1.0% recommended).

Works well on (tested by user)
BTCUSD (Bitcoin), EURUSD, GBPJPY, NAS100/US100, USDJPY, AUDUSD, XAGUSD (Silver), US30 (Dow), JP225 (Nikkei), EURGBP, NZDUSD, EURCHF, USDCHF.

How to use
Apply to D1 charts. Review once per day after the daily close and execute next session open to mirror backtest assumptions. Best used as a portfolio strategy across multiple uncorrelated markets. Use the EMA alignment above as a discretionary regime filter to reduce false breakouts.

Notes
For educational use. Markets involve risk; past performance does not guarantee future results. Use responsible position sizing.

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.