Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Donchian Channel Strategy Idea

A Pine Script v4 strategy built on Highest (high, 10) and Lowest (low, 10). It has 6 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. 5 settings; defaults include High Period 10, Low Period 10 and Stop-loss (%) 5.0.

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 Channel Strategy Idea repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 19 of 19 trades.
How did Donchian Channel Strategy Idea do on BTCUSDT 1D with default settings?
−1.16%
From 26 Jan 2024 to 21 Oct 2026, over 62 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Donchian Channel Strategy Idea 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 Channel Strategy Idea use a stop loss?
Yes
strategy.exit sets a stop on line 38, 39.
Does Donchian Channel Strategy Idea run in Zeal Terminal?
Yes
It compiles in 11 ms and runs 1,000 bars in 29 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • 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 (5)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$989$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.
Net profit
−1.16%
−$11.56
Buy and hold
+102.5%
same period
Closed trades
62
21 won · 41 lost
Profitable
33.9%
of closed trades
Profit factor
0.99
gross profit ÷ gross loss
Max drawdown
38.95%
−$535.00

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

    No slippage

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

  • Note

    Uses an argument v6 removed

    when = on line 28, 29, 31, 32. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 49

    transp = on line 49. 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.
  • 4 strategy calls use the when = argument (line 28, 29, 31, 32). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 20: highest → ta.highest
  • Line 21: lowest → ta.lowest
  • Line 49: transp = 90 → color.new(colors, 90)
⋯// © QuantCT-//@version=4+//@version=5strategy("Donchian Channel Strategy Idea",⋯// ____ Logic-highest_high = highest(high, high_period)+highest_high = ta.highest(high, high_period)-lowest_low = lowest(low, low_period)+lowest_low = ta.lowest(low, low_period)base_line = (highest_high + lowest_low) / 2⋯plot(base_line, color=color.silver)-fill(highest_high_plot, lowest_low_plot, color=colors, transp=90)+fill(highest_high_plot, lowest_low_plot, color=color.new(colors, 90))

Clean v5

VerifiedDownload the v5 script

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

  • Line 14: input() → input.int()
  • Line 15: input() → input.int()
  • Line 16: input() → input.bool()
  • Line 17: input() → input.float()
  • Line 18: input() → input.bool()
  • Line 28: when = enter_long → if block
3 more edits
  • Line 29: when = exit_long → if block
  • Line 31: when = enter_short → if block
  • Line 32: when = exit_short → if block
⋯// ____ Inputs-high_period = input(title="High Period", defval=10) +high_period = input.int(title="High Period", defval=10) -low_period = input(title="Low Period", defval=10)+low_period = input.int(title="Low Period", defval=10)-long_only = input(title="Long Only", defval=false)+long_only = input.bool(title="Long Only", defval=false)-slp = input(title="Stop-loss (%)", minval=1.0, maxval=25.0, defval=5.0)+slp = input.float(title="Stop-loss (%)", minval=1.0, maxval=25.0, defval=5.0)-use_sl = input(title="Use Stop-Loss", defval=false)+use_sl = input.bool(title="Use Stop-Loss", defval=false)// ____ Logic⋯exit_short = (close > base_line)-strategy.entry("Long", strategy.long, when=enter_long)+if enter_long+    strategy.entry("Long", strategy.long)-strategy.close("Long", when=exit_long) +if exit_long+    strategy.close("Long") if (not long_only)-    strategy.entry("Short", strategy.short, when=enter_short)+    if enter_short+        strategy.entry("Short", strategy.short)-    strategy.close("Short", when=exit_short) +    if exit_short+        strategy.close("Short")    ⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 62 before, 98 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © QuantCT-//@version=5+//@version=6strategy("Donchian Channel Strategy Idea",⋯

Settings

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

SettingDefaultType and rangeFeeds
High Period10inthighest_high
Low Period10intlowest_low
Long Onlyfalseboolentry Short close Short line 30
Stop-loss (%)5.0float · min 1.0 · max 25.0sl_long sl_short
Use Stop-Lossfalseboolexit SL exit SL line 37

What it calculates

  • Highest (highest, ta.highest in v5)high, High Period (10)highest_high · line 20
  • Lowest (lowest, ta.lowest in v5)low, Low Period (10)lowest_low · line 21

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 datahigh_periodHigh Periodsetting · 10lowlowprice datalow_periodLow Periodsetting · 10slpStop-loss (%)setting · 5.0closecloseprice datahighest_highHighest→ highest_highlowest_lowLowest→ lowest_lowbase_linebase_linevaluesl_long, sl_shortsl_long · sl_short2 valuesenter_longenter_longconditionexit_longexit_longconditionenter_shortenter_shortconditionexit_shortexit_shortconditioncolorsColourcolorsentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeentry:ShortOpen Shortstrategy.entryclose:ShortClose Shortstrategy.closeexit:SLexit SLstrategy.exitplot:46plotplotplot:47plotplotplot:48plotplotfill:49Fillfill

Order rules

OrderFires whenBy defaultLine
Open Long longenter_long(close > highest_high[1])On28
Close Longexit_long(close < base_line)On29
Open Short shortenter_short(close < lowest_low[1])On31
Close Shortexit_short(close > base_line)On32
Exit SL stop(use_sl)On38
Exit SL stop(use_sl)On39

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.

19/19trades 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−1.2%+102.5%6234%0.9939.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−13.2%+5.5%6526%0.7719.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+16.3%+9.8%6035%1.0542.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+4.7%+8.4%5829%1.0626.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+26.3%+16.7%5939%1.1246.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.5%+21.5%6433%1.0115.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−22.3%+148.3%6327%0.8757.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−7.0%+17.1%6231%0.8919.9%8 May 2026 – 21 Oct 2026

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

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (High Period 6, Low Period 17) made +19.3% before 26 Dec 2025 and +32.0% after it, against +7.3% for the defaults. 27% of the 64 combinations made money in-sample and 98% out-of-sample.

Before 26 Dec 2025 · in-sample
Low Period ↓ · High Period →567910121417
5−28%−21%−23%−24%−27%−23%−20%−27%
6−20%−6%−7%−9%−13%−5%−3%−21%
7−6%+2%+6%−2%−6%−0%+13%−0%
9−15%−8%−3%−7%−12%−8%−6%−15%
10−14%−4%+0%−3%−9%−5%−4%−12%
12−14%−12%−7%−7%−13%−9%−8%−16%
14−0%+8%+13%+5%−2%+3%+6%+0%
17+11%+19%+11%+1%−5%+1%+6%+5%
From 26 Dec 2025 · out-of-sample
Low Period ↓ · High Period →567910121417
5+2%+12%+8%+9%+9%+17%+15%+16%
6+5%+12%+8%+10%+10%+20%+17%+22%
7+0%+7%+6%+8%+7%+18%+16%+24%
9+6%+12%+13%+12%+11%+12%+4%+19%
10+5%+10%+9%+8%+7%+9%+1%+16%
12+8%+14%+13%+11%+10%+12%−0%+10%
14+20%+24%+25%+16%+15%+19%+5%+18%
17+30%+32%+30%+20%+16%+22%+8%+14%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1828%−$81.81
Sideways market3238%$100.17
Falling market1233%−$29.91

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

How bad could the drawdown be?

53.2%

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

0%61%
All 62 trades
SideEntryExitBarsP&L
long8 Feb 2024 44,349.6024 Feb 2024 50,744.2016$142.47
long27 Feb 2024 54,476.5017 Mar 2024 65,300.6019$224.95
short20 Mar 2024 61,937.4021 Mar 2024 67,840.501−$132.38
long9 Apr 2024 71,620.0013 Apr 2024 67,116.504−$79.39
short14 Apr 2024 63,924.5023 Apr 2024 66,819.309−$54.07
short1 May 2024 60,672.004 May 2024 62,882.003−$41.78
long16 May 2024 66,206.5027 May 2024 68,507.7011$35.19
long6 Jun 2024 71,108.009 Jun 2024 69,310.503−$29.28
short15 Jun 2024 66,044.001 Jul 2024 62,772.0016$51.20
short5 Jul 2024 57,050.0013 Jul 2024 57,889.108−$18.10
long15 Jul 2024 60,797.9031 Jul 2024 66,188.0016$95.62
short3 Aug 2024 61,498.309 Aug 2024 61,686.006−$5.44
long24 Aug 2024 64,037.2028 Aug 2024 59,415.004−$87.48
short2 Sep 2024 57,301.8010 Sep 2024 57,042.008$3.34
long14 Sep 2024 60,498.001 Oct 2024 63,327.6017$49.94
short2 Oct 2024 60,804.9012 Oct 2024 62,540.0010−$34.68
long15 Oct 2024 66,084.0026 Oct 2024 66,698.3011$8.72
long29 Oct 2024 69,962.203 Nov 2024 69,374.705−$11.16
long7 Nov 2024 75,572.0026 Nov 2024 93,010.0019$255.84
long16 Dec 2024 104,464.0019 Dec 2024 100,204.003−$57.99
long7 Jan 2025 102,236.008 Jan 2025 96,954.601−$69.83
long18 Jan 2025 104,077.0027 Jan 2025 102,620.009−$19.29
short3 Feb 2025 97,700.604 Feb 2025 101,329.001−$47.38
short25 Feb 2025 91,552.903 Mar 2025 94,270.006−$36.76
long20 Mar 2025 86,845.9029 Mar 2025 84,424.409−$33.52
short7 Apr 2025 78,430.0010 Apr 2025 82,615.203−$60.83
long22 Apr 2025 87,516.205 May 2025 94,277.6013$79.27
long9 May 2025 103,262.0030 May 2025 105,590.0021$23.69
short31 May 2025 103,985.008 Jun 2025 105,552.008−$19.07
long10 Jun 2025 110,263.0015 Jun 2025 105,415.005−$51.39
short22 Jun 2025 102,120.0024 Jun 2025 105,334.002−$35.62
long30 Jun 2025 108,357.0021 Jul 2025 117,265.0021$84.20
short2 Aug 2025 113,298.008 Aug 2025 117,472.006−$43.29
long11 Aug 2025 119,294.0015 Aug 2025 118,295.004−$10.71
short20 Aug 2025 112,873.004 Sep 2025 111,706.0015$9.51
long11 Sep 2025 113,960.0022 Sep 2025 115,232.0011$10.46
short23 Sep 2025 112,651.0030 Sep 2025 114,312.007−$17.79
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$54.40
long27 Oct 2025 114,559.0030 Oct 2025 110,021.003−$41.99
short5 Nov 2025 101,497.0011 Nov 2025 106,011.006−$45.09
short15 Nov 2025 94,594.0027 Nov 2025 90,484.0012$39.25
long4 Dec 2025 93,429.9013 Dec 2025 90,268.409−$34.40
short16 Dec 2025 86,432.1022 Dec 2025 88,658.906−$25.64
long5 Jan 2026 91,529.7010 Jan 2026 90,641.305−$10.24
long14 Jan 2026 95,414.0019 Jan 2026 93,673.105−$17.84
short21 Jan 2026 88,427.7014 Feb 2026 68,854.0024$194.98
short24 Feb 2026 64,656.0026 Feb 2026 67,988.002−$57.37
long5 Mar 2026 72,666.807 Mar 2026 68,114.002−$65.63
long17 Mar 2026 74,884.7020 Mar 2026 69,930.003−$64.78
short23 Mar 2026 67,859.006 Apr 2026 69,034.2014−$16.82
long8 Apr 2026 71,924.2020 Apr 2026 73,801.8012$21.55
long5 May 2026 79,861.0014 May 2026 79,313.609−$7.50
short17 May 2026 78,148.1026 May 2026 77,322.009$8.09
short29 May 2026 73,617.5013 Jun 2026 63,580.0015$121.28
long15 Jun 2026 65,746.4019 Jun 2026 62,958.004−$44.75
short25 Jun 2026 61,078.003 Jul 2026 61,560.008−$9.16
long6 Jul 2026 63,650.0014 Jul 2026 62,334.508−$21.40
long15 Jul 2026 65,044.0025 Jul 2026 64,140.0010−$14.54
long20 Aug 2026 69,334.802 Sep 2026 77,439.0013$107.24
short16 Sep 2026 75,644.5019 Sep 2026 80,883.903−$73.45
long19 Sep 2026 80,883.9029 Sep 2026 83,500.0010$29.73
short9 Oct 2026 81,754.5019 Oct 2026 82,116.0010−$5.89

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 Channel Strategy Idea this page—v4 strategy−1.2%6239.0%
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%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msYes 1,000 bars in 29 msNot measured
PineTSNo v5 and v6 only—Not 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. 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/// © QuantCT//@version=4strategy("Donchian Channel Strategy Idea",         shorttitle="Donchian",          overlay=true,         pyramiding=0,              default_qty_type=strategy.percent_of_equity,          default_qty_value=100,          initial_capital=1000,                    commission_type=strategy.commission.percent,          commission_value=0.075)// ____ Inputshigh_period = input(title="High Period", defval=10) low_period = input(title="Low Period", defval=10)long_only = input(title="Long Only", defval=false)slp = input(title="Stop-loss (%)", minval=1.0, maxval=25.0, defval=5.0)use_sl = input(title="Use Stop-Loss", defval=false)// ____ Logichighest_high = highest(high, high_period)lowest_low = lowest(low, low_period)base_line = (highest_high + lowest_low) / 2    enter_long = (close > highest_high[1])exit_long = (close < base_line)enter_short = (close < lowest_low[1])exit_short = (close > base_line)strategy.entry("Long", strategy.long, when=enter_long)strategy.close("Long", when=exit_long) if (not long_only)    strategy.entry("Short", strategy.short, when=enter_short)    strategy.close("Short", when=exit_short)    // ____ SLsl_long = strategy.position_avg_price * (1- (slp/100))sl_short = strategy.position_avg_price * (1 + (slp/100))if (use_sl)    strategy.exit(id="SL", from_entry="Long", stop=sl_long)    strategy.exit(id="SL", from_entry="Short", stop=sl_short)    // ____ Plotscolors =  strategy.position_size > 0 ? #27D600 : strategy.position_size < 0 ? #E30202 : color.orangehighest_high_plot = plot(highest_high, color=colors)lowest_low_plot = plot(lowest_low, color=colors)plot(base_line, color=color.silver)fill(highest_high_plot, lowest_low_plot, color=colors, transp=90)