Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Donchian Breakout Strategy

A Pine Script v5 strategy built on Highest (high, 20) and Lowest (low, 20). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 10% of equity and pays 0.05% commission. 3 settings; defaults include Entry channel length 20 and Exit channel length 10.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does Donchian Breakout Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did Donchian Breakout Strategy do on BTCUSDT 1D with default settings?
+2.59%
From 26 Jan 2024 to 21 Oct 2026, over 19 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does Donchian Breakout Strategy have?
2
Breakout up; Breakout down.
Does Donchian Breakout Strategy run in Pine Script v6?
Yes
Same 19 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does Donchian Breakout Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 26, 28.

BTCUSDT · 1D · default settings

  • Entry high
  • Entry low
  • Exit low
  • Exit high
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,259$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
+2.59%
$258.92
Buy and hold
+102.5%
same period
Closed trades
19
8 won · 11 lost
Profitable
42.1%
of closed trades
Profit factor
1.43
gross profit ÷ gross loss
Max drawdown
2.78%
−$289.96

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

Nothing to point out.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Entry channel length20int · min 2entryHigh entryLow
Exit channel length10int · min 1exitHigh exitLow
Trade the short sidefalseboolentry Short line 22

What it calculates

  • Highesthigh, Entry channel length (20)entryHigh · line 12
  • Lowestlow, Entry channel length (20)entryLow · line 13
  • Highesthigh, Exit channel length (10)exitHigh · line 14
  • Lowestlow, Exit channel length (10)exitLow · line 15

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

highhighprice dataentryLenEntry channel lengthsetting · 20lowlowprice dataexitLenExit channel lengthsetting · 10closecloseprice dataentryHighHighest→ entryHighentryLowLowest→ entryLowexitHighHighest→ exitHighexitLowLowest→ exitLowgoLonggoLongconditiongoShortgoShortconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Long exitexit Long exitstrategy.exitexit:Short exitexit Short exitstrategy.exitplot:30Entry highplotplot:31Entry lowplotplot:32Exit lowplotplot:33Exit highplotalertcondition:35Breakout upalertconditionalertcondition:36Breakout downalertcondition

Order rules

OrderFires whenBy defaultLine
Open Long longgoLongOn21
Open Short shortgoShort and allowShortsOn23
Exit Long exit stopstrategy.position_size > 0On26
Exit Short exit stopstrategy.position_size < 0On28

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Breakout upalertconditionClose broke above the entry channel35
Breakout downalertconditionClose broke below the entry channel36

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

6/6trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+2.6%+102.5%1942%1.432.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.0%+5.5%1429%1.580.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.2%+9.8%1839%0.985.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+2.0%+8.4%1338%2.060.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+6.6%+16.7%1753%2.173.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+3.8%+21.5%1250%3.271.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.8%+148.3%1833%1.115.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.3%+17.1%1822%1.151.8%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market650%$13.78
Sideways market1040%$264.00
Falling market333%−$18.86

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

4.3%

The 95th percentile of the worst drawdown when the same 19 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.8% to 4.3%; the tick is what actually happened, 2.4%. Order luck alone moves it this much.

0%5%
All 19 trades
SideEntryExitBarsP&L
long27 Feb 2024 54,476.5019 Mar 2024 64,533.0021$183.42
long16 May 2024 66,206.5011 Jun 2024 66,670.0026$6.10
long16 Jul 2024 64,724.101 Aug 2024 63,456.7016−$20.95
long24 Aug 2024 64,037.3030 Aug 2024 57,787.306−$100.16
long19 Sep 2024 61,760.001 Oct 2024 62,350.0012$8.60
long16 Oct 2024 67,074.105 Dec 2024 90,791.1050$354.95
long16 Dec 2024 104,464.0020 Dec 2024 94,150.004−$103.94
long18 Jan 2025 104,077.002 Feb 2025 97,777.8015−$63.48
long23 Apr 2025 93,443.0031 May 2025 103,985.0038$114.67
long10 Jul 2025 111,234.0025 Jul 2025 115,737.0015$40.94
long14 Aug 2025 123,306.0019 Aug 2025 115,879.005−$63.75
long17 Sep 2025 116,789.0022 Sep 2025 113,430.005−$30.79
long2 Oct 2025 118,595.0010 Oct 2025 111,561.008−$62.22
long5 Jan 2026 91,529.8020 Jan 2026 89,694.6015−$21.58
long5 Mar 2026 72,666.8022 Mar 2026 68,793.3017−$55.56
long14 Apr 2026 74,418.0016 May 2026 78,754.6032$58.28
long15 Jul 2026 65,044.0031 Jul 2026 62,742.5016−$37.24
long20 Aug 2026 69,334.8011 Sep 2026 76,264.0022$100.89
long22 Sep 2026 86,620.008 Oct 2026 82,563.0016−$49.26

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Donchian Breakout Strategy this page—v5 strategy+2.6%192.8%
Alex Days HiLo Rajib by 14rajibhighest lowestv4 strategyNo trades on this market
Donchian Strat EXMO by pskoroplashighest lowestv4 strategy+12.1%2268.0%
Average Highest High and Lowest Low Swinger Strategy by exlux99lowest highestv4 strategy+6.4%2049.6%
Highest High and Lowest Low Channel Strategy by ceyhunhighest lowestv5 strategy−3.7%267.9%
Donchian Channels System [racer8] by racer8highest lowestv4 strategy−3.2%3643.6%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Yes

Same 19 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © Zeal Terminal-//@version=5+//@version=6strategy("Donchian Breakout Strategy", shorttitle = "Donchian Breakout", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 28 msYes 1,000 bars in 52 msNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Written by Zeal Terminal and published under the Mozilla Public License 2.0.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5strategy("Donchian Breakout Strategy", shorttitle = "Donchian Breakout", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1) // Not investment advice. Enters on a close beyond the entry channel and exits// on a close beyond the shorter exit channel on the other side.entryLen    = input.int(20, "Entry channel length", minval = 2)exitLen     = input.int(10, "Exit channel length", minval = 1)allowShorts = input.bool(false, "Trade the short side") entryHigh = ta.highest(high, entryLen)[1]entryLow  = ta.lowest(low, entryLen)[1]exitHigh  = ta.highest(high, exitLen)[1]exitLow   = ta.lowest(low, exitLen)[1] goLong  = close > entryHighgoShort = close < entryLow if goLong    strategy.entry("Long", strategy.long)if goShort and allowShorts    strategy.entry("Short", strategy.short) if strategy.position_size > 0    strategy.exit("Long exit", "Long", stop = exitLow)if strategy.position_size < 0    strategy.exit("Short exit", "Short", stop = exitHigh) plot(entryHigh, "Entry high", color = #26a69a)plot(entryLow, "Entry low", color = #ef5350)plot(exitLow, "Exit low", color = color.new(#26a69a, 60), style = plot.style_stepline)plot(exitHigh, "Exit high", color = color.new(#ef5350, 60), style = plot.style_stepline) alertcondition(goLong,  "Breakout up",   "Close broke above the entry channel")alertcondition(goShort, "Breakout down", "Close broke below the entry channel")