Pine Script v4 · Strategy
Donchian Channel Strategy [for free bot]
A Pine Script v4 strategy built on Highest (10), Highest or Lowest (10) and Lowest (20). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 20% of equity and pays 0.036% commission. 16 settings; defaults include Channel Period for Long enter position 10, Channel Period for Long exit position 10 and Take Profit (%) for Long position 2.5.
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 [for free bot] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 33 of 33 trades.
- How did Donchian Channel Strategy [for free bot] do on BTCUSDT 1D with default settings?
- −9.43%
- From 26 Jan 2024 to 21 Oct 2026, over 128 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Donchian Channel Strategy [for free bot] 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 [for free bot] use a stop loss?
- Yes
- strategy.exit sets a stop on line 51, 56.
- Does Donchian Channel Strategy [for free bot] run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 50 ms, in the browser.
BTCUSDT · 1D · default settings
- Buy Enter
- Buy Exit
- Sell Enter
- Sell Exit
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −9.43%
- −$94.26
- Buy and hold
- +102.5%
- same period
- Closed trades
- 128
- 71 won · 57 lost
- Profitable
- 55.5%
- of closed trades
- Profit factor
- 0.80
- gross profit ÷ gross loss
- Max drawdown
- 12.51%
- −$125.11
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.
-
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 49, 51, 54, 56. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 36
transp = on line 36, 38. 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 49, 51, 54, 56). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 128 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 30: highest → ta.highest
- Line 31: highest → ta.highest
- Line 31: lowest → ta.lowest
- Line 31: lowest → ta.lowest
- Line 32: lowest → ta.lowest
5 more edits
- Line 33: highest → ta.highest
- Line 33: lowest → ta.lowest
- Line 33: highest → ta.highest
- Line 36: transp = 50 → color.new(color.blue, 50)
- Line 38: transp = 50 → color.new(color.red, 50)
⋯// Strategy testing and optimisation for free trading bot -//@version=4+//@version=5strategy("Donchian Channel Strategy [for free bot]", overlay=true, default_qty_type= strategy.percent_of_equity, initial_capital = 1000, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.036)⋯// Long&Short Levels-BuyEnter = highest(buyPeriodEnter)+BuyEnter = ta.highest(buyPeriodEnter)-BuyExit = isMiddleBuy ? ((highest(buyPeriodExit) + lowest(buyPeriodExit)) / 2): lowest(buyPeriodExit)+BuyExit = isMiddleBuy ? ((ta.highest(buyPeriodExit) + ta.lowest(buyPeriodExit)) / 2): ta.lowest(buyPeriodExit)-SellEnter = lowest(sellPeriodEnter)+SellEnter = ta.lowest(sellPeriodEnter)-SellExit = isMiddleSell ? ((highest(sellPeriodExit) + lowest(sellPeriodExit)) / 2): highest(sellPeriodExit)+SellExit = isMiddleSell ? ((ta.highest(sellPeriodExit) + ta.lowest(sellPeriodExit)) / 2): ta.highest(sellPeriodExit)// Plot Dataplot(BuyEnter, style=plot.style_line, linewidth=2, color=color.blue, title="Buy Enter")-plot(BuyExit, style=plot.style_line, linewidth=1, color=color.blue, title="Buy Exit", transp=50)+plot(BuyExit, style=plot.style_line, linewidth=1, color=color.new(color.blue, 50), title="Buy Exit")plot(SellEnter, style=plot.style_line, linewidth=2, color=color.red, title="Sell Enter")-plot(SellExit, style=plot.style_line, linewidth=1, color=color.red, title="Sell Exit", transp=50)+plot(SellExit, style=plot.style_line, linewidth=1, color=color.new(color.red, 50), title="Sell Exit")// Calc Take Profits⋯Same 128 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.bool()
- Line 10: input() → input.float()
- Line 11: input() → input.bool()
- Line 13: input() → input.int()
14 more edits
- Line 14: input() → input.int()
- Line 15: input() → input.bool()
- Line 16: input() → input.float()
- Line 17: input() → input.bool()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 21: input() → input.int()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
- Line 26: input() → input.int()
- Line 49: when = strategy.position_size == 0 → if block
- Line 51: when = strategy.position_size > 0 → if block
- Line 54: when = strategy.position_size == 0 → if block
- Line 56: when = strategy.position_size < 0 → if block
⋯//Long optopns-buyPeriodEnter = input(10, "Channel Period for Long enter position")+buyPeriodEnter = input.int(10, "Channel Period for Long enter position")-buyPeriodExit = input(10, "Channel Period for Long exit position")+buyPeriodExit = input.int(10, "Channel Period for Long exit position")-isMiddleBuy = input(true, "Is exit on Base Line? If 'no' - exit on bottom line")+isMiddleBuy = input.bool(true, "Is exit on Base Line? If 'no' - exit on bottom line")-takeProfitBuy = input(2.5, "Take Profit (%) for Long position")+takeProfitBuy = input.float(2.5, "Take Profit (%) for Long position")-isBuy = input(true, "Allow Long?")+isBuy = input.bool(true, "Allow Long?")//Short Options-sellPeriodEnter = input(20, "Channel Period for Short enter position")+sellPeriodEnter = input.int(20, "Channel Period for Short enter position")-sellPeriodExit = input(20, "Channel Period for Short exit position")+sellPeriodExit = input.int(20, "Channel Period for Short exit position")-isMiddleSell = input(true, "Is exit on Base Line? If 'no' - exit on upper line")+isMiddleSell = input.bool(true, "Is exit on Base Line? If 'no' - exit on upper line")-takeProfitSell = input(2.5, "Take Profit (%) for Short position")+takeProfitSell = input.float(2.5, "Take Profit (%) for Short position")-isSell = input(true, "Allow Short?")+isSell = input.bool(true, "Allow Short?")// Test Start-startYear = input(2005, "Test Start Year")+startYear = input.int(2005, "Test Start Year")-startMonth = input(1, "Test Start Month")+startMonth = input.int(1, "Test Start Month")-startDay = input(1, "Test Start Day")+startDay = input.int(1, "Test Start Day")startTest = timestamp(startYear,startMonth,startDay,0,0)//Test End-endYear = input(2050, "Test End Year")+endYear = input.int(2050, "Test End Year")-endMonth = input(12, "Test End Month")+endMonth = input.int(12, "Test End Month")-endDay = input(30, "Test End Day")+endDay = input.int(30, "Test End Day")endTest = timestamp(endYear,endMonth,endDay,23,59)⋯if isBuy and timeRange- strategy.entry("Long", strategy.long, stop = BuyEnter, when = strategy.position_size == 0) + if strategy.position_size == 0+ strategy.entry("Long", strategy.long, stop = BuyEnter) -strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TakeProfitBuy, when = strategy.position_size > 0)+if strategy.position_size > 0+ strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TakeProfitBuy)// Short Positionif isSell and timeRange- strategy.entry("Short", strategy.short, stop = SellEnter, when = strategy.position_size == 0) + if strategy.position_size == 0+ strategy.entry("Short", strategy.short, stop = SellEnter) -strategy.exit("Short Exit", "Short", stop=SellExit, limit = TakeProfitSell, when = strategy.position_size < 0)+if strategy.position_size < 0+ strategy.exit("Short Exit", "Short", stop=SellExit, limit = TakeProfitSell)// Close & Cancel when over End of the Test⋯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: 128 before, 128 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.
⋯// Strategy testing and optimisation for free trading bot -//@version=5+//@version=6strategy("Donchian Channel Strategy [for free bot]", overlay=true, default_qty_type= strategy.percent_of_equity, initial_capital = 1000, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.036)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Channel Period for Long enter position | 10 | int | BuyEnter |
| Channel Period for Long exit position | 10 | int | BuyExit |
| Is exit on Base Line? If 'no' - exit on bottom line | true | bool | BuyExit |
| Take Profit (%) for Long position | 2.5 | float | TakeProfitBuy |
| Allow Long? | true | bool | entry Long line 48 |
| Channel Period for Short enter position | 20 | int | SellEnter |
| Channel Period for Short exit position | 20 | int | SellExit |
| Is exit on Base Line? If 'no' - exit on upper line | true | bool | SellExit |
| Take Profit (%) for Short position | 2.5 | float | TakeProfitSell |
| Allow Short? | true | bool | entry Short line 53 |
| Test Start Year | 2005 | int | startTest |
| Test Start Month | 1 | int | startTest |
| Test Start Day | 1 | int | startTest |
| Test End Year | 2050 | int | endTest |
| Test End Month | 12 | int | endTest |
| Test End Day | 30 | int | endTest |
What it calculates
- Highest (
highest,ta.highestin v5)Channel Period for Long enter position (10)BuyEnter · line 30 - Highest / Lowest (
highest,ta.highestin v5)Channel Period for Long exit position (10)BuyExit · line 31 - Lowest (
lowest,ta.lowestin v5)Channel Period for Short enter position (20)SellEnter · line 32 - Highest / Lowest (
highest,ta.highestin v5)Channel Period for Short exit position (20)SellExit · line 33
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | strategy.position_size == 0 | On | 49 |
| Exit Long Exit stop and limit | strategy.position_size > 0 | On | 51 |
| Open Short short | strategy.position_size == 0 | On | 54 |
| Exit Short Exit stop and limit | strategy.position_size < 0 | On | 56 |
| Close | time > endTest | On | 59 |
| cancel_all | time > endTest | On | 60 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −9.4% | +102.5% | 128 | 55% | 0.80 | 12.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.9% | +5.5% | 93 | 32% | 1.07 | 2.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +4.2% | +9.8% | 133 | 68% | 1.08 | 10.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −2.7% | +8.4% | 107 | 38% | 0.87 | 4.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −5.4% | +16.7% | 141 | 72% | 0.91 | 21.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −4.3% | +21.5% | 112 | 41% | 0.84 | 5.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +5.1% | +148.3% | 125 | 65% | 1.12 | 9.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −1.8% | +17.1% | 101 | 33% | 0.89 | 3.5% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 45 | 49% | −$73.63 |
| Sideways market | 61 | 56% | −$18.05 |
| Falling market | 22 | 68% | −$2.57 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
18.4%
The 95th percentile of the worst drawdown when the same 128 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 10.8% to 18.4%; the tick is what actually happened, 12.5%. Order luck alone moves it this much.
All 128 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Jan 2024 41,823.50 | 27 Jan 2024 41,823.50 | 0 | −$0.14 |
| short | 27 Jan 2024 41,823.50 | 15 Feb 2024 51,795.20 | 19 | −$47.83 |
| long | 20 Feb 2024 52,816.60 | 23 Feb 2024 50,643.00 | 3 | −$7.97 |
| long | 26 Feb 2024 52,985.00 | 27 Feb 2024 54,476.50 | 1 | $5.18 |
| long | 28 Feb 2024 57,588.20 | 29 Feb 2024 62,432.10 | 1 | $15.82 |
| long | 4 Mar 2024 64,000.00 | 5 Mar 2024 68,245.70 | 1 | $12.66 |
| long | 8 Mar 2024 69,000.00 | 11 Mar 2024 70,725.00 | 3 | $4.74 |
| long | 12 Mar 2024 72,800.00 | 15 Mar 2024 66,391.00 | 3 | −$17.43 |
| long | 26 Mar 2024 71,150.00 | 2 Apr 2024 67,384.80 | 7 | −$10.35 |
| long | 8 Apr 2024 71,366.00 | 9 Apr 2024 68,645.50 | 1 | −$7.41 |
| short | 13 Apr 2024 63,772.30 | 14 Apr 2024 62,178.00 | 1 | $4.60 |
| short | 17 Apr 2024 60,660.60 | 22 Apr 2024 66,199.00 | 5 | −$17.52 |
| short | 30 Apr 2024 59,600.00 | 1 May 2024 58,110.00 | 1 | $4.54 |
| long | 6 May 2024 64,820.00 | 8 May 2024 61,026.40 | 2 | −$11.12 |
| long | 15 May 2024 65,500.00 | 17 May 2024 67,137.50 | 2 | $4.50 |
| long | 19 May 2024 67,451.20 | 20 May 2024 69,137.50 | 1 | $4.52 |
| long | 21 May 2024 71,515.60 | 23 May 2024 66,364.10 | 2 | −$13.62 |
| long | 4 Jun 2024 70,687.60 | 7 Jun 2024 69,214.00 | 3 | −$3.98 |
| short | 11 Jun 2024 66,312.20 | 12 Jun 2024 69,024.00 | 1 | −$7.65 |
| short | 14 Jun 2024 66,051.00 | 18 Jun 2024 64,399.70 | 4 | $4.43 |
| short | 21 Jun 2024 64,060.00 | 24 Jun 2024 62,458.50 | 3 | $4.45 |
| short | 4 Jul 2024 58,402.00 | 5 Jul 2024 56,941.90 | 1 | $4.47 |
| long | 14 Jul 2024 60,498.20 | 15 Jul 2024 62,010.70 | 1 | $4.49 |
| long | 16 Jul 2024 64,900.00 | 19 Jul 2024 66,522.50 | 3 | $4.51 |
| long | 20 Jul 2024 67,386.00 | 25 Jul 2024 64,553.40 | 5 | −$7.98 |
| long | 27 Jul 2024 68,474.60 | 30 Jul 2024 66,768.30 | 3 | −$4.74 |
| short | 4 Aug 2024 59,850.00 | 5 Aug 2024 58,161.00 | 1 | $5.07 |
| long | 23 Aug 2024 61,820.90 | 24 Aug 2024 64,037.20 | 1 | $6.50 |
| long | 25 Aug 2024 64,955.00 | 27 Aug 2024 61,393.70 | 2 | −$10.35 |
| short | 4 Sep 2024 56,078.50 | 6 Sep 2024 54,676.60 | 2 | $4.48 |
| long | 13 Sep 2024 59,809.70 | 17 Sep 2024 61,304.90 | 4 | $4.50 |
| long | 18 Sep 2024 61,320.00 | 19 Sep 2024 62,853.00 | 1 | $4.52 |
| long | 20 Sep 2024 63,850.00 | 26 Sep 2024 65,446.30 | 6 | $4.54 |
| long | 27 Sep 2024 65,839.00 | 30 Sep 2024 64,424.00 | 3 | −$4.17 |
| short | 10 Oct 2024 59,828.10 | 11 Oct 2024 62,722.00 | 1 | −$9.19 |
| long | 14 Oct 2024 64,478.20 | 15 Oct 2024 66,090.10 | 1 | $4.50 |
| long | 16 Oct 2024 67,950.00 | 23 Oct 2024 65,784.80 | 7 | −$6.07 |
| long | 28 Oct 2024 69,519.50 | 29 Oct 2024 71,257.50 | 1 | $4.49 |
| long | 6 Nov 2024 73,620.10 | 7 Nov 2024 75,572.00 | 1 | $4.79 |
| long | 8 Nov 2024 76,850.00 | 10 Nov 2024 78,771.20 | 2 | $4.54 |
| long | 11 Nov 2024 81,500.00 | 12 Nov 2024 88,648.00 | 1 | $16.33 |
| long | 13 Nov 2024 89,940.00 | 18 Nov 2024 92,188.50 | 5 | $4.64 |
| long | 19 Nov 2024 93,265.60 | 21 Nov 2024 95,597.30 | 2 | $4.66 |
| long | 22 Nov 2024 98,988.00 | 25 Nov 2024 93,330.70 | 3 | −$11.16 |
| long | 4 Dec 2024 98,871.80 | 5 Dec 2024 101,344.00 | 1 | $4.63 |
| long | 15 Dec 2024 104,088.00 | 16 Dec 2024 106,690.00 | 1 | $4.65 |
| long | 17 Dec 2024 107,793.00 | 18 Dec 2024 101,252.00 | 1 | −$11.82 |
| short | 30 Dec 2024 92,232.50 | 6 Jan 2025 99,941.70 | 7 | −$16.04 |
| long | 6 Jan 2025 99,963.70 | 7 Jan 2025 102,463.00 | 1 | $4.62 |
| short | 9 Jan 2025 91,530.40 | 14 Jan 2025 95,990.50 | 5 | −$9.29 |
| long | 17 Jan 2025 102,724.00 | 19 Jan 2025 105,292.00 | 2 | $4.52 |
| long | 20 Jan 2025 106,422.00 | 26 Jan 2025 103,462.00 | 6 | −$5.33 |
| short | 3 Feb 2025 94,346.20 | 4 Feb 2025 101,329.00 | 1 | −$13.89 |
| long | 21 Feb 2025 98,826.00 | 22 Feb 2025 96,182.00 | 1 | −$5.03 |
| short | 24 Feb 2025 93,388.10 | 25 Feb 2025 91,053.40 | 1 | $4.42 |
| short | 26 Feb 2025 86,051.00 | 27 Feb 2025 83,899.70 | 1 | $4.44 |
| short | 28 Feb 2025 82,256.00 | 2 Mar 2025 88,866.80 | 2 | −$14.91 |
| short | 10 Mar 2025 78,258.50 | 19 Mar 2025 85,803.00 | 9 | −$17.57 |
| long | 20 Mar 2025 87,000.00 | 22 Mar 2025 83,696.80 | 2 | −$6.86 |
| long | 24 Mar 2025 87,453.70 | 28 Mar 2025 84,950.00 | 4 | −$5.16 |
| short | 6 Apr 2025 81,134.70 | 7 Apr 2025 78,430.00 | 1 | $5.71 |
| long | 13 Apr 2025 85,905.00 | 21 Apr 2025 88,052.60 | 8 | $4.27 |
| long | 22 Apr 2025 88,466.00 | 23 Apr 2025 93,443.00 | 1 | $9.82 |
| long | 25 Apr 2025 94,696.10 | 1 May 2025 97,063.50 | 6 | $4.34 |
| long | 2 May 2025 97,424.00 | 4 May 2025 94,777.80 | 2 | −$5.01 |
| long | 8 May 2025 97,895.70 | 9 May 2025 103,262.00 | 1 | $9.67 |
| long | 10 May 2025 104,361.00 | 19 May 2025 106,970.00 | 9 | $4.39 |
| long | 20 May 2025 107,109.00 | 21 May 2025 109,786.00 | 1 | $4.41 |
| long | 22 May 2025 110,797.00 | 25 May 2025 106,682.00 | 3 | −$6.91 |
| short | 5 Jun 2025 102,000.00 | 8 Jun 2025 106,176.00 | 3 | −$7.55 |
| long | 9 Jun 2025 106,795.00 | 10 Jun 2025 110,263.00 | 1 | $5.70 |
| short | 22 Jun 2025 100,372.00 | 23 Jun 2025 104,365.00 | 1 | −$7.32 |
| long | 29 Jun 2025 108,272.00 | 4 Jul 2025 107,576.00 | 5 | −$1.28 |
| long | 9 Jul 2025 110,529.00 | 10 Jul 2025 113,292.00 | 1 | $4.34 |
| long | 11 Jul 2025 116,868.00 | 14 Jul 2025 119,790.00 | 3 | $4.37 |
| short | 1 Aug 2025 114,723.00 | 7 Aug 2025 116,370.00 | 6 | −$2.73 |
| long | 10 Aug 2025 118,922.00 | 11 Aug 2025 121,896.00 | 1 | $4.37 |
| long | 13 Aug 2025 122,335.00 | 14 Aug 2025 118,159.00 | 1 | −$6.31 |
| short | 22 Aug 2025 111,920.00 | 26 Aug 2025 109,122.00 | 4 | $4.37 |
| short | 29 Aug 2025 108,667.00 | 5 Sep 2025 112,915.00 | 7 | −$7.20 |
| long | 10 Sep 2025 113,385.00 | 12 Sep 2025 116,219.00 | 2 | $4.35 |
| long | 15 Sep 2025 116,666.00 | 21 Sep 2025 115,665.00 | 6 | −$1.67 |
| short | 25 Sep 2025 109,977.00 | 29 Sep 2025 113,260.00 | 4 | −$5.50 |
| long | 1 Oct 2025 115,819.00 | 2 Oct 2025 118,715.00 | 1 | $4.34 |
| long | 3 Oct 2025 121,022.00 | 5 Oct 2025 124,048.00 | 2 | $4.36 |
| long | 6 Oct 2025 125,708.00 | 10 Oct 2025 119,428.00 | 4 | −$9.14 |
| short | 10 Oct 2025 108,620.00 | 12 Oct 2025 114,100.00 | 2 | −$9.24 |
| long | 26 Oct 2025 114,000.00 | 29 Oct 2025 111,252.00 | 3 | −$4.39 |
| short | 4 Nov 2025 103,528.00 | 5 Nov 2025 100,940.00 | 1 | $4.27 |
| short | 13 Nov 2025 98,944.40 | 14 Nov 2025 96,470.80 | 1 | $4.29 |
| short | 16 Nov 2025 94,012.40 | 17 Nov 2025 91,662.10 | 1 | $4.31 |
| short | 18 Nov 2025 91,220.00 | 19 Nov 2025 88,939.50 | 1 | $4.33 |
| short | 20 Nov 2025 88,608.00 | 21 Nov 2025 86,392.80 | 1 | $4.36 |
| long | 3 Dec 2025 93,092.00 | 5 Dec 2025 88,986.40 | 2 | −$8.07 |
| long | 9 Dec 2025 94,150.00 | 12 Dec 2025 90,386.70 | 3 | −$7.26 |
| long | 2 Jan 2026 90,406.10 | 5 Jan 2026 92,666.20 | 3 | $4.30 |
| long | 13 Jan 2026 94,789.10 | 14 Jan 2026 97,158.80 | 1 | $4.32 |
| short | 21 Jan 2026 87,550.40 | 29 Jan 2026 85,361.70 | 8 | $4.34 |
| short | 30 Jan 2026 83,383.30 | 31 Jan 2026 81,298.70 | 1 | $4.37 |
| short | 1 Feb 2026 75,719.90 | 3 Feb 2026 73,826.90 | 2 | $4.39 |
| short | 4 Feb 2026 72,945.50 | 5 Feb 2026 71,121.90 | 1 | $4.41 |
| short | 6 Feb 2026 62,345.00 | 25 Feb 2026 66,670.60 | 19 | −$12.79 |
| long | 2 Mar 2026 69,988.80 | 3 Mar 2026 66,303.10 | 1 | −$9.59 |
| long | 4 Mar 2026 70,096.00 | 5 Mar 2026 72,666.80 | 1 | $6.39 |
| long | 16 Mar 2026 73,913.70 | 17 Mar 2026 75,761.60 | 1 | $4.35 |
| short | 27 Mar 2026 65,618.50 | 7 Apr 2026 69,836.20 | 11 | −$11.70 |
| long | 8 Apr 2026 72,761.00 | 13 Apr 2026 74,580.00 | 5 | $4.31 |
| long | 14 Apr 2026 74,900.00 | 17 Apr 2026 76,772.50 | 3 | $4.33 |
| long | 22 Apr 2026 78,333.00 | 27 Apr 2026 76,598.60 | 5 | −$4.10 |
| long | 4 May 2026 79,485.70 | 5 May 2026 81,472.80 | 1 | $4.33 |
| long | 6 May 2026 81,791.50 | 12 May 2026 80,445.00 | 6 | −$3.08 |
| short | 22 May 2026 76,051.00 | 28 May 2026 74,149.70 | 6 | $4.34 |
| short | 29 May 2026 72,582.80 | 1 Jun 2026 70,768.20 | 3 | $4.36 |
| short | 2 Jun 2026 70,686.70 | 3 Jun 2026 66,760.80 | 1 | $9.90 |
| short | 4 Jun 2026 64,092.50 | 5 Jun 2026 62,490.20 | 1 | $4.43 |
| long | 14 Jun 2026 64,764.30 | 15 Jun 2026 66,383.40 | 1 | $4.45 |
| short | 24 Jun 2026 59,130.90 | 3 Jul 2026 62,546.20 | 9 | −$10.78 |
| long | 4 Jul 2026 63,239.10 | 13 Jul 2026 62,974.40 | 9 | −$0.89 |
| long | 14 Jul 2026 64,700.00 | 17 Jul 2026 63,572.30 | 3 | −$3.30 |
| long | 20 Jul 2026 65,600.00 | 24 Jul 2026 64,614.20 | 4 | −$2.85 |
| long | 9 Aug 2026 65,409.60 | 10 Aug 2026 63,874.70 | 1 | −$4.37 |
| long | 19 Aug 2026 65,474.50 | 20 Aug 2026 69,334.80 | 1 | $10.47 |
| long | 21 Aug 2026 73,400.00 | 22 Aug 2026 78,338.00 | 1 | $12.11 |
| long | 24 Aug 2026 79,500.00 | 1 Sep 2026 78,512.30 | 8 | −$2.42 |
| long | 3 Sep 2026 81,478.90 | 4 Sep 2026 79,282.00 | 1 | −$5.09 |
| short | 15 Sep 2026 76,046.60 | 18 Sep 2026 78,634.00 | 3 | −$6.36 |
| long | 18 Sep 2026 80,560.00 | 21 Sep 2026 82,574.00 | 3 | $4.44 |
| short | 15 Oct 2026 80,393.60 | 21 Oct 2026 83,510.00 | 6 | −$7.21 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Donchian Channel Strategy [for free bot] this page | — | v4 strategy | −9.4% | 128 | 12.5% |
| Alex Days HiLo Rajib by 14rajib | highest lowest | v4 strategy | No trades on this market | ||
| Donchian Strat EXMO by pskoroplas | highest lowest | v4 strategy | +12.1% | 22 | 68.0% |
| Average Highest High and Lowest Low Swinger Strategy by exlux99 | lowest highest | v4 strategy | +6.4% | 20 | 49.6% |
| Highest High and Lowest Low Channel Strategy by ceyhun | highest lowest | v5 strategy | −3.7% | 26 | 7.9% |
| Donchian Channels System [racer8] by racer8 | highest lowest | v4 strategy | −3.2% | 36 | 43.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | Yes 1,000 bars in 50 ms | Not measured |
| PineTS | No 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/// © algotradingcc// Strategy testing and optimisation for free trading bot //@version=4strategy("Donchian Channel Strategy [for free bot]", overlay=true, default_qty_type= strategy.percent_of_equity, initial_capital = 1000, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.036)//Long optopnsbuyPeriodEnter = input(10, "Channel Period for Long enter position")buyPeriodExit = input(10, "Channel Period for Long exit position")isMiddleBuy = input(true, "Is exit on Base Line? If 'no' - exit on bottom line")takeProfitBuy = input(2.5, "Take Profit (%) for Long position")isBuy = input(true, "Allow Long?")//Short OptionssellPeriodEnter = input(20, "Channel Period for Short enter position")sellPeriodExit = input(20, "Channel Period for Short exit position")isMiddleSell = input(true, "Is exit on Base Line? If 'no' - exit on upper line")takeProfitSell = input(2.5, "Take Profit (%) for Short position")isSell = input(true, "Allow Short?")// Test StartstartYear = input(2005, "Test Start Year")startMonth = input(1, "Test Start Month")startDay = input(1, "Test Start Day")startTest = timestamp(startYear,startMonth,startDay,0,0)//Test EndendYear = input(2050, "Test End Year")endMonth = input(12, "Test End Month")endDay = input(30, "Test End Day")endTest = timestamp(endYear,endMonth,endDay,23,59)timeRange = time > startTest and time < endTest ? true : false// Long&Short LevelsBuyEnter = highest(buyPeriodEnter)BuyExit = isMiddleBuy ? ((highest(buyPeriodExit) + lowest(buyPeriodExit)) / 2): lowest(buyPeriodExit)SellEnter = lowest(sellPeriodEnter)SellExit = isMiddleSell ? ((highest(sellPeriodExit) + lowest(sellPeriodExit)) / 2): highest(sellPeriodExit)// Plot Dataplot(BuyEnter, style=plot.style_line, linewidth=2, color=color.blue, title="Buy Enter")plot(BuyExit, style=plot.style_line, linewidth=1, color=color.blue, title="Buy Exit", transp=50)plot(SellEnter, style=plot.style_line, linewidth=2, color=color.red, title="Sell Enter")plot(SellExit, style=plot.style_line, linewidth=1, color=color.red, title="Sell Exit", transp=50)// Calc Take ProfitsTakeProfitBuy = 0.0TakeProfitSell = 0.0if strategy.position_size > 0 TakeProfitBuy := strategy.position_avg_price*(1 + takeProfitBuy/100) if strategy.position_size < 0 TakeProfitSell := strategy.position_avg_price*(1 - takeProfitSell/100)// Long Position if isBuy and timeRange strategy.entry("Long", strategy.long, stop = BuyEnter, when = strategy.position_size == 0) strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TakeProfitBuy, when = strategy.position_size > 0)// Short Positionif isSell and timeRange strategy.entry("Short", strategy.short, stop = SellEnter, when = strategy.position_size == 0) strategy.exit("Short Exit", "Short", stop=SellExit, limit = TakeProfitSell, when = strategy.position_size < 0)// Close & Cancel when over End of the Testif time > endTest strategy.close_all() strategy.cancel_all()