The Donchian Channel Breakout strategy reacts when price moves beyond its highest high or lowest low over a fixed lookback window — the same idea behind the classic "Turtle" trading rules. Traders use it as a structured way to define a breakout level rather than eyeballing it. It is an educational framework for studying trend continuation; it is not predictive, and like all strategies it can produce losses. If you want to turn this idea into checked Pine Script v6, ForexCodes' Strategy Validator flags look-ahead bias, repainting, and intent mismatches before you ever rely on a backtest — try it free.
A Donchian Channel is built from three lines: the highest high over the last N bars (upper band), the lowest low over the last N bars (lower band), and the midpoint between them. The bands form a rolling box around recent price.
The breakout idea is simple: when price closes above the upper band it has made a new N-bar high, which traders interpret as potential upward momentum; when it closes below the lower band it has made a new N-bar low, interpreted as potential downward momentum. The strategy enters in the breakout direction and then manages exits — common choices are the channel midline, the opposite band, or a separate, shorter exit channel (the approach used in the example below).
A key detail: the current bar's own high/low can inflate the band and block a clean signal, so many implementations compute the channel from prior bars (an offset lookback) — the approach used in the example. A larger lookback (e.g. 55) gives fewer, slower signals; a smaller one (e.g. 20) reacts faster but produces more false breakouts. The right setting depends on the instrument, timeframe, and how a trader chooses to define a trend.
//@version=6
strategy("Donchian Channel Breakout (Educational)", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
// Inputs
entryLen = input.int(55, "Entry channel length", minval = 1)
exitLen = input.int(20, "Exit channel length", minval = 1)
useShort = input.bool(true, "Allow short entries")
// Channel bands computed from PRIOR bars (offset by 1) so a new extreme can register cleanly.
// Note: ta.highest(high[1], len) and ta.highest(len)[1] are equivalent ways to exclude the current bar.
upperEntry = ta.highest(high[1], entryLen)
lowerEntry = ta.lowest(low[1], entryLen)
upperExit = ta.highest(high[1], exitLen)
lowerExit = ta.lowest(low[1], exitLen)
midline = math.avg(upperEntry, lowerEntry)
// Breakout conditions (confirmed on bar close).
longBreak = close > upperEntry
shortBreak = close < lowerEntry
// Entries
if longBreak
strategy.entry("Long", strategy.long)
if useShort and shortBreak
strategy.entry("Short", strategy.short)
// Exits: leave a long if price closes below the shorter exit channel's low; mirror for shorts.
if close < lowerExit
strategy.close("Long")
if close > upperExit
strategy.close("Short")
// Plots
plot(upperEntry, "Upper (entry)", color = color.teal)
plot(lowerEntry, "Lower (entry)", color = color.maroon)
plot(midline, "Midline", color = color.gray)
// Note: backtest results are illustrative only — past behaviour does not predict future results.There is no single correct value. The classic Turtle rules used 20 and 55 bars, with 20 reacting faster and 55 capturing larger swings. Shorter periods give more signals but more false breakouts; longer periods give fewer, slower signals. Test several settings across different instruments and timeframes, and avoid tuning the number until a backtest looks perfect — that tends to overfit.
If the highest high includes the bar you're evaluating, that bar's own high helps define the upper band, so a clean 'new high' breakout can be hard to register or can behave inconsistently. Computing the band from prior bars (e.g. ta.highest(high[1], length), or equivalently ta.highest(length)[1]) lets a genuinely new extreme trigger the signal. This is a common, defensible choice, though some traders prefer the inclusive version — both should be tested deliberately, not by accident.
No strategy can promise that, and we won't claim it. The Donchian breakout is an educational framework for defining breakout levels and studying trend continuation; it is not predictive, and trading carries real risk of loss. Any backtest you see is illustrative only and past behaviour does not guarantee future results. Treat it as a structured idea to study and validate, not a guaranteed outcome.
These are exactly the issues that quietly break breakout backtests: an offset that accidentally peeks at future bars, or an exit that relies on a still-forming intrabar value. ForexCodes' Strategy Validator turns a plain-English or AI-generated strategy into checked Pine Script v6 and flags look-ahead bias, repainting, and intent mismatches before you trust the results. It's educational software, not advice — try it free on your own Donchian setup.
Educational & software only — not financial advice, not a recommendation to trade. Backtests are illustrative; past performance does not predict future results. Trading involves substantial risk of loss.