Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Donchian Channels Strategy by KrisWaters

A Pine Script v4 strategy built on Highest (high, 20), Lowest (low, 10) and ATR (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 100% of equity and pays 0.075% commission. 15 settings; defaults include From Day 1, From Month 1 and From Year 2017.

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 Channels Strategy by KrisWaters 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 Channels Strategy by KrisWaters do on BTCUSDT 1D with default settings?
+55.76%
From 26 Jan 2024 to 21 Oct 2026, over 21 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Donchian Channels Strategy by KrisWaters be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Donchian Channels Strategy by KrisWaters use a stop loss?
Yes
strategy.exit sets a stop on line 52, 56.
Does Donchian Channels Strategy by KrisWaters run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 88 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • 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 (15)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,558$2,025Equity from $1,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. Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 51, 55) so the engine trades the way the script says.
Net profit
+55.76%
$557.56
Buy and hold
+102.5%
same period
Closed trades
21
9 won · 12 lost
Profitable
42.9%
of closed trades
Profit factor
1.74
gross profit ÷ gross loss
Max drawdown
23.31%
−$368.63

One run with the author's default settings, $1,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.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    4 settings have no label

    In the settings dialog longUpperLength (line 24), longLowerLength (line 25), shortUpperLength (line 26), shortLowerLength (line 27) show an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses transp =, which v5 removed line 39

    transp = on line 39, 40. v5 folds the transparency into the colour with color.new(c, transp).

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames highest → ta.highest, lowest → ta.lowest, atr → ta.atr, max → math.max, min → math.min.

v4 → v5

Verified

Same 21 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 29: highest → ta.highest
  • Line 30: lowest → ta.lowest
  • Line 31: highest → ta.highest
  • Line 32: lowest → ta.lowest
  • Line 39: transp = 95 → color.new(color.green, 95)
6 more edits
  • Line 40: transp = 95 → color.new(color.red, 95)
  • Line 43: atr → ta.atr
  • Line 51: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 52: max → math.max
  • Line 55: strategy.entry(…, false) → strategy.entry(…, strategy.short)
  • Line 56: min → math.min
⋯// © kriswaters-//@version=4+//@version=5strategy("Donchian Channels Strategy by KrisWaters", overlay=true,⋯// Donchian indicator calculations-longUpperValue = highest(high,longUpperLength)+longUpperValue = ta.highest(high,longUpperLength)-longLowerValue = lowest(low,longLowerLength)+longLowerValue = ta.lowest(low,longLowerLength)-shortUpperValue = highest(high,shortUpperLength)+shortUpperValue = ta.highest(high,shortUpperLength)-shortLowerValue = lowest(low,shortLowerLength)+shortLowerValue = ta.lowest(low,shortLowerLength)// Plot Donchian Channels⋯// Styling-fill(uLong,lLong, color=color.green, transp=95, title="Long Arkaplan")+fill(uLong,lLong, color=color.new(color.green, 95), title="Long Arkaplan")-fill(uShort,lShort, color=color.red, transp=95, title="Short Arkaplan")+fill(uShort,lShort, color=color.new(color.red, 95), title="Short Arkaplan")// Stop-loss value calculationsatrMultiplier = 2.0-atrValue = atr(20)+atrValue = ta.atr(20)longStopValue = open - (atrMultiplier*atrValue)⋯if canEnterLong and na(longUpperValue) != true and na(longLowerValue) != true and window()-    strategy.entry("Long", true, stop=longUpperValue)+    strategy.entry("Long", strategy.long, stop=longUpperValue)-    strategy.exit("Long Exit", "Long", stop=useAtrAsStopRule ? max(longLowerValue,longStopValue) : longLowerValue)+    strategy.exit("Long Exit", "Long", stop=useAtrAsStopRule ? math.max(longLowerValue,longStopValue) : longLowerValue)    if canEnterShort and na(shortUpperValue) != true and na(shortLowerValue) != true and window()-    strategy.entry("Short", false, stop=shortLowerValue)+    strategy.entry("Short", strategy.short, stop=shortLowerValue)-    strategy.exit("Short Exit", "Short", stop=useAtrAsStopRule ? min(shortUpperValue,shortStopValue) : shortUpperValue)+    strategy.exit("Short Exit", "Short", stop=useAtrAsStopRule ? math.min(shortUpperValue,shortStopValue) : shortUpperValue)

Clean v5

VerifiedDownload the v5 script

Same 21 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
9 more edits
  • Line 18: input() → input.bool()
  • Line 19: input() → input.bool()
  • Line 20: input() → input.bool()
  • Line 21: input() → input.bool()
  • Line 22: input() → input.bool()
  • Line 24: input() → input.int()
  • Line 25: input() → input.int()
  • Line 26: input() → input.int()
  • Line 27: input() → input.int()
⋯// Date filter-FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+FromDay   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+FromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-FromYear  = input(defval = 2017, title = "From Year", minval = 1900)+FromYear  = input.int(defval = 2017, title = "From Year", minval = 1900)-ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+ToDay     = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+ToMonth   = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-ToYear    = input(defval = 9999, title = "To Year", minval = 2017)+ToYear    = input.int(defval = 9999, title = "To Year", minval = 2017)start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window⋯// Strategy Settings-canEnterLong = input(true, title="Can Enter Long Position")+canEnterLong = input.bool(true, title="Can Enter Long Position")-canEnterShort = input(false, title="Can Enter Short Position")+canEnterShort = input.bool(false, title="Can Enter Short Position")-showLongChannel = input(true, title="Show Donchian Long Channels")+showLongChannel = input.bool(true, title="Show Donchian Long Channels")-showShortChannel = input(false , title="Show Donchian Short Channels")+showShortChannel = input.bool(false , title="Show Donchian Short Channels")-useAtrAsStopRule = input(false, title="Enable ATR Stop Rule") +useAtrAsStopRule = input.bool(false, title="Enable ATR Stop Rule") // DonCcian Channel Lengths-longUpperLength = input(20, minval=1)+longUpperLength = input.int(20, minval=1)-longLowerLength = input(10, minval=1)+longLowerLength = input.int(10, minval=1)-shortUpperLength = input(10, minval=1)+shortUpperLength = input.int(10, minval=1)-shortLowerLength = input(20, minval=1)+shortLowerLength = input.int(20, minval=1)// Donchian indicator calculations⋯

Does it run in Pine Script v6?

Yes

Same 21 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

⋯// © kriswaters-//@version=5+//@version=6strategy("Donchian Channels Strategy by KrisWaters", overlay=true,⋯

Settings

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

SettingDefaultType and rangeFeeds
From Day1int · min 1 · max 31start
From Month1int · min 1 · max 12start
From Year2017int · min 1900start
To Day1int · min 1 · max 31finish
To Month1int · min 1 · max 12finish
To Year9999int · min 2017finish
Can Enter Long Positiontrueboolentry Long exit Long Exit line 50
Can Enter Short Positionfalseboolentry Short exit Short Exit line 54
Show Donchian Long ChannelstruebooluLong lLong plot
Show Donchian Short ChannelsfalsebooluShort lShort plot
Enable ATR Stop Rulefalseboolplot exit Long Exit exit Short Exit
Long Upper Length (no label in the script)20int · min 1longUpperValue
Long Lower Length (no label in the script)10int · min 1longLowerValue
Short Upper Length (no label in the script)10int · min 1shortUpperValue
Short Lower Length (no label in the script)20int · min 1shortLowerValue

What it calculates

  • Highest (highest, ta.highest in v5)high, Long Upper Length (20)longUpperValue · line 29
  • Lowest (lowest, ta.lowest in v5)low, Long Lower Length (10)longLowerValue · line 30
  • Highest (highest, ta.highest in v5)high, Short Upper Length (10)shortUpperValue · line 31
  • Lowest (lowest, ta.lowest in v5)low, Short Lower Length (20)shortLowerValue · line 32
  • ATR (atr, ta.atr in v5)20atrValue · line 43

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 datalongUpperLengthLong Upper Lengthsetting · 20lowlowprice datalongLowerLengthLong Lower Lengthsetting · 10shortUpperLengthShort Upper Lengthsetting · 10shortLowerLengthShort Lower Lengthsetting · 20high · low · closehigh · low · closeprice dataFromYearFrom Yearsetting · 2017FromMonthFrom Monthsetting · 1FromDayFrom Daysetting · 1ToYearTo Yearsetting · 9999ToMonthTo Monthsetting · 1ToDayTo Daysetting · 1openopenprice datalongUpperValueHighest→ longUpperValuelongLowerValueLowest→ longLowerValueshortUpperValueHighest→ shortUpperValueshortLowerValueLowest→ shortLowerValueatrValueATR→ atrValuestartstartvaluefinishfinishvaluelongStopValue, shortStopValuelongStopValue · shortSt…2 valuesentry:LongOpen Longstrategy.entryexit:Long Exitexit Long Exitstrategy.exitentry:ShortOpen Shortstrategy.entryexit:Short Exitexit Short Exitstrategy.exitplot:34plotplotplot:35plotplotplot:36plotplotplot:37plotplotfill:Long ArkaplanLong Arkaplanfillfill:Short ArkaplanShort Arkaplanfillplot:47plotplotplot:48plotplot

Order rules

OrderFires whenBy defaultLine
Open Long longcanEnterLong and na(longUpperValue) != true and na(longLowerValue) != true and window()On51
Exit Long Exit stopcanEnterLong and na(longUpperValue) != true and na(longLowerValue) != true and window()On52
Open Short shortcanEnterShort and na(shortUpperValue) != true and na(shortLowerValue) != true and window()On55
Exit Short Exit stopcanEnterShort and na(shortUpperValue) != true and na(shortLowerValue) != true and window()On56

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

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+55.8%+102.5%2143%1.7423.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.2%+5.5%2035%1.1911.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+65.2%+9.8%2040%1.4837.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+22.8%+8.4%1741%1.897.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+148.3%+16.7%1953%2.4932.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+10.2%+21.5%2030%1.2612.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−32.5%+148.3%2631%0.7060.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+7.1%+17.1%2232%1.3211.6%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 market757%$55.18
Sideways market1040%$550.60
Falling market425%−$48.23

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

How bad could the drawdown be?

34.0%

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

0%39%
All 21 trades
SideEntryExitBarsP&L
long15 Feb 2024 52,043.7017 Mar 2024 64,780.0031$242.86
long8 Apr 2024 71,769.5013 Apr 2024 64,493.105−$127.68
long15 May 2024 65,500.0011 Jun 2024 67,257.5027$28.21
long15 Jul 2024 63,861.801 Aug 2024 63,456.7017−$8.96
long23 Aug 2024 62,745.1030 Aug 2024 57,860.007−$89.89
long17 Sep 2024 61,167.001 Oct 2024 62,357.9014$18.74
long14 Oct 2024 66,498.005 Dec 2024 90,791.1052$386.26
long15 Dec 2024 104,088.0020 Dec 2024 94,256.505−$138.88
long17 Jan 2025 102,724.0027 Jan 2025 99,550.0010−$42.41
long22 Apr 2025 88,500.0030 May 2025 104,185.0038$222.53
long2 Jul 2025 108,952.0025 Jul 2025 115,737.0023$90.46
long11 Aug 2025 120,248.0018 Aug 2025 115,879.007−$59.74
long15 Sep 2025 116,666.0022 Sep 2025 114,384.007−$31.99
long1 Oct 2025 117,900.0010 Oct 2025 112,656.009−$68.38
long9 Dec 2025 94,150.0014 Dec 2025 87,719.305−$99.05
long2 Jan 2026 90,634.6020 Jan 2026 90,128.4018−$9.35
long4 Mar 2026 70,983.0021 Mar 2026 68,793.4017−$42.40
long8 Apr 2026 72,761.0015 May 2026 78,754.6037$102.58
long14 Jul 2026 64,700.0028 Jul 2026 63,100.0014−$35.96
long19 Aug 2026 65,474.5011 Sep 2026 76,264.0023$217.98
long21 Sep 2026 82,300.008 Oct 2026 82,563.0017$2.63

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 Channels Strategy by KrisWaters this page—v4 strategy+55.8%2123.3%
Aggresive Scalper-Swing Crypto Strategy by exlux99lowest highest atrv4 strategy−7.4%316.0%
Chandelier Exit - Strategy by melihtunaatr highest lowestv4 strategy−34.8%1143.2%
ETF trader by FX_mindsatr lowest highestv4 strategy+78.3%1732.7%
Chandelier Exit by Zeal Terminalatr highest lowestv5 indicatorindicator
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99highest lowest atrv5 strategy+10.8%578.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msWith a workaround 1,000 bars in 88 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 51, 55) so the engine trades the way the script says.

“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. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © kriswaters//@version=4strategy("Donchian Channels Strategy by KrisWaters", overlay=true,         initial_capital=1000, currency='USD', default_qty_type=strategy.percent_of_equity,         default_qty_value=100, commission_type= strategy.commission.percent, commission_value=0.075) // Date filterFromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)FromYear  = input(defval = 2017, title = "From Year", minval = 1900)ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)ToYear    = input(defval = 9999, title = "To Year", minval = 2017)start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start windowfinish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish windowwindow()  => time >= start and time <= finish ? true : false // create function "within window of time"// Strategy SettingscanEnterLong = input(true, title="Can Enter Long Position")canEnterShort = input(false, title="Can Enter Short Position")showLongChannel = input(true, title="Show Donchian Long Channels")showShortChannel = input(false , title="Show Donchian Short Channels")useAtrAsStopRule = input(false, title="Enable ATR Stop Rule") // DonCcian Channel LengthslongUpperLength = input(20, minval=1)longLowerLength = input(10, minval=1)shortUpperLength = input(10, minval=1)shortLowerLength = input(20, minval=1)// Donchian indicator calculationslongUpperValue = highest(high,longUpperLength)longLowerValue = lowest(low,longLowerLength)shortUpperValue = highest(high,shortUpperLength)shortLowerValue = lowest(low,shortLowerLength)// Plot Donchian ChannelsuLong = plot(showLongChannel ? longUpperValue : na, color=color.green, offset=1)lLong = plot(showLongChannel ? longLowerValue : na, color=color.green, offset=1)uShort = plot(showShortChannel ? shortUpperValue : na, color=color.red, offset=1)lShort = plot(showShortChannel ? shortLowerValue : na, color=color.red, offset=1)// Stylingfill(uLong,lLong, color=color.green, transp=95, title="Long Arkaplan")fill(uShort,lShort, color=color.red, transp=95, title="Short Arkaplan")// Stop-loss value calculationsatrMultiplier = 2.0atrValue = atr(20)longStopValue = open - (atrMultiplier*atrValue)shortStopValue = open + (atrMultiplier*atrValue)// Plot stop-loss lineplot(useAtrAsStopRule ? longStopValue : na, color=color.red, linewidth=2, offset=1)plot(useAtrAsStopRule ? shortStopValue : na, color=color.red, linewidth=2, offset=1)// Long and Short Position Rulesif canEnterLong and na(longUpperValue) != true and na(longLowerValue) != true and window()    strategy.entry("Long", true, stop=longUpperValue)    strategy.exit("Long Exit", "Long", stop=useAtrAsStopRule ? max(longLowerValue,longStopValue) : longLowerValue)    if canEnterShort and na(shortUpperValue) != true and na(shortLowerValue) != true and window()    strategy.entry("Short", false, stop=shortLowerValue)    strategy.exit("Short Exit", "Short", stop=useAtrAsStopRule ? min(shortUpperValue,shortStopValue) : shortUpperValue)