Strategy · Pine Script v5 · On the chart

Donchian Channel Breakout

by AlnurM

Donchian Channel Breakout is a Pine Script v5 strategy drawn on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code41
Settings3inputs
LicenceMIT
Last update7 months ago22 Mar 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

41 lines of Pine Script v5 from references/pinescript-examples/breakout.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

breakout.pine
//@version=5
strategy("Donchian Channel Breakout", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)

// === INPUTS ===
dcLength = input.int(20, "Donchian Channel Period", minval=5, maxval=200)
atrLength = input.int(14, "ATR Period for Trailing Stop", minval=5, maxval=50)
atrMultiplier = input.float(2.0, "ATR Trailing Stop Multiplier", minval=0.5, maxval=5.0, step=0.1)

// === INDICATORS ===
dcUpper = ta.highest(high, dcLength)
dcLower = ta.lowest(low, dcLength)
dcMiddle = (dcUpper + dcLower) / 2
atrValue = ta.atr(atrLength)

// === SIGNALS ===
// Long on upper channel breakout
longCondition = ta.crossover(close, dcUpper[1])
// Short on lower channel breakout
shortCondition = ta.crossunder(close, dcLower[1])

// === EXECUTION ===
if longCondition
    strategy.entry("Long", strategy.long)

if shortCondition
    strategy.entry("Short", strategy.short)

// Trailing stop using ATR
if strategy.position_size > 0
    trailStop = close - atrValue * atrMultiplier
    strategy.exit("Long Trail", "Long", stop=trailStop)

if strategy.position_size < 0
    trailStop = close + atrValue * atrMultiplier
    strategy.exit("Short Trail", "Short", stop=trailStop)

// === PLOTTING ===
plot(dcUpper, "DC Upper", color=color.green, linewidth=2)
plot(dcLower, "DC Lower", color=color.red, linewidth=2)
plot(dcMiddle, "DC Middle", color=color.gray, linewidth=1, style=plot.style_cross)
fill(plot(dcUpper, display=display.none), plot(dcLower, display=display.none), color=color.new(color.blue, 90))

Overview

Donchian Channel Breakout enters long when close crosses above the previous upper Donchian band and short when close crosses below the previous lower band, reversing with the opposite signal. An ATR trailing stop closes the position; the stop sits a user-set ATR multiple away from the current close. Channel length, ATR length, and the multiplier are the main inputs. Size defaults to full equity with a percent commission, and there is no separate take-profit target.

Details

Published by

AlnurM on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Breakout, Volatility & bands, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Donchian Channel Periodint20dcLength
ATR Period for Trailing Stopint14atrLength
ATR Trailing Stop Multiplierfloat2.0atrMultiplier
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
16 stars

This strategy trades Donchian breakouts measured on weekly bars while orders execute on the chart timeframe. It allows long and short entries when price breaks the prior weekly channel and exits against the shorter weekly channel. Position size risks a set per

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 4: Weekly Donchian
11 stars

Calculates upper and lower Donchian Channel bands over a customizable lookback length and plots them on the main price chart. At a specified exchange hour, the strategy places a long buy stop order at the upper Donchian Channel level. Unfilled pending orders a

Strategy v6 BreakoutSupport & resistance
Updated 5 months ago · Apache-2.0 GitHub repository of Estrategia Donchian Breakout
6 stars

This overlay strategy builds independent timed session ranges and marks range, trendline, mean, VWAP, and high-low levels when those displays are enabled. It enters on range breakouts and exits with strategy exits, choosing among range, ATR, fixed-point, and r

Strategy v5 Sessions & timeBreakout
Updated 7 months ago · None stated GitHub repository of MSG Enhanced LEGO System Strategy

The Range Percent Breakout Strategy identifies range contraction and inside bar patterns where the current bar's range is within a specified percentage threshold of the previous bar. When this condition is met while flat, breakout levels are established above

Strategy v5 BreakoutVolatility & bands
Updated 5 months ago · None stated GitHub repository of Range Percent Breakout Strategy

Breakout Strategy

by Web3Degenerate
2 stars

This strategy detects price breakouts beyond the high or low of a higher timeframe (default Daily) on an intraday chart. When the close crosses above the higher-timeframe high or below its low, it enters long or short, limiting execution to one breakout per di

Strategy v5 BreakoutSupport & resistance
Updated 2 years ago · None stated GitHub repository of Breakout Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers