Strategy · Pine Script v6 · On the chart

Donchian Channel Breakout

by pineforge-4pass· code credited to PineForge contributors 2026

This strategy tracks price breakouts using Donchian Channels calculated from the highest highs and lowest lows over configurable lookback periods.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code42
Settings2inputs
LicenceApache-2.0
Last update7 days ago23 Oct 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

42 lines of Pine Script v6 from validation/ta-donchian-channel-breakout-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 10 — Donchian channel breakout
// Purpose: parity test for ta.highest / ta.lowest band construction with the
// `[1]`-shifted entry comparison (yesterday's channel, today's close).
//
//@version=6
strategy("Donchian Channel Breakout", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

// === Inputs ===
entryLen = input.int(20, "Entry Channel Length", minval=5)
exitLen  = input.int(10, "Exit Channel Length", minval=3)

// === Donchian Channels ===
entryUpper = ta.highest(high, entryLen)
entryLower = ta.lowest(low, entryLen)
entryMid   = (entryUpper + entryLower) / 2

exitUpper  = ta.highest(high, exitLen)
exitLower  = ta.lowest(low, exitLen)

// === Breakout signals ===
longCond  = close > entryUpper[1]
shortCond = close < entryLower[1]

// === Strategy ===
if longCond
    strategy.entry("Long", strategy.long)
if shortCond
    strategy.entry("Short", strategy.short)

// === Exit on opposite channel ===
if strategy.position_size > 0 and close < exitLower[1]
    strategy.close("Long")
if strategy.position_size < 0 and close > exitUpper[1]
    strategy.close("Short")

plot(entryUpper, "Entry Upper", color=color.green)
plot(entryLower, "Entry Lower", color=color.red)
plot(entryMid, "Mid", color=color.gray)

Overview

Donchian Channel Breakout plots the upper, lower, and mid entry channels directly on the price chart. A long entry triggers when the bar close breaks above the previous bar's entry channel, while a short entry triggers below the lower entry channel. Positions exit when price crosses the shorter exit channel bounds. Settings allow users to adjust the entry and exit channel lengths. Note that the strategy operates without fixed stop-loss orders.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
Entry Channel Lengthint20entryLen
Exit Channel Lengthint10exitLen
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 7 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 12 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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated 2 days ago · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
106 stars

This overlay strategy plots a two-timeframe Ichimoku setup on the price chart, with Tenkan, Kijun, Chikou, and Kumo from a base higher timeframe and an optional highest-timeframe cloud. It allows two entries in the same direction and uses ATR-based trailing st

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 2Tier Ichimoku Pyramiding [Takazudo]

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers