strategy · on price · open source
Donchian channel breakout strategy (20 / 10, Turtle-style)
Turtle-style Donchian breakout: buy a close above the 20-bar high, exit below the 10-bar low, 2.5×ATR stop. Code plus a backtest with next-bar fills and costs. Deepwick Script runs a subset of Pine Script.
What the Donchian Breakout strategy does
Turtle-style breakout: go long when price closes above the highest high of the last N bars, exit on a close below the lowest low of a shorter window. Includes an ATR stop.
Open the Strategy Tester to see trades, equity and drawdown.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
Entry channel | 20 | 2 | — |
Exit channel | 10 | 2 | — |
ATR stop | 2.5 | — | — |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("Donchian Breakout Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.05)
entryLen = input.int(20, "Entry channel", minval=2)
exitLen = input.int(10, "Exit channel", minval=2)
atrMult = input.float(2.5, "ATR stop", step=0.1)
hi = ta.highest(high, entryLen)[1]
lo = ta.lowest(low, exitLen)[1]
plot(hi, "Entry level", color=color.green)
plot(lo, "Exit level", color=color.red)
if strategy.position_size == 0 and close > hi
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Stop", stop=strategy.position_avg_price - ta.atr(14) * atrMult)
if close < lo
strategy.close("Long", comment="Channel exit")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
Does the Donchian breakout work intraday?
It can be tested on any timeframe from 1 minute to weekly. On low timeframes more breakouts fail and costs weigh more per trade, so compare the trades count and fees in the table before drawing conclusions.
Is this the original Turtle Trading system?
It borrows the Turtle idea (20-bar breakout entry, 10-bar exit, ATR-based stop) but is long-only, uses 20% of equity per trade and has no pyramiding or unit sizing, so it is a simplified version.
No comments yet.
Sign in to comment.