strategy · on price · open source
Donchian Breakout Strategy
Running…
Loading chart…
About
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.
Source code
//@version=5
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")
No comments yet.
Sign in to comment.