Pine Script v4 · Strategy
Channel Break [for free bot]
A Pine Script v4 strategy built on Highest (13), Highest or Lowest (13) and Lowest (18). 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.075% commission. 11 settings; defaults include Channel Period for Long position 13, Channel Period for Short position 18 and Take Profit (%) for position 46.
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 Channel Break [for free bot] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 18 of 18 trades.
- How did Channel Break [for free bot] do on BTCUSDT 1D with default settings?
- +4.38%
- From 26 Jan 2024 to 21 Oct 2026, over 85 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Channel Break [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 Channel Break [for free bot] use a stop loss?
- Yes
- strategy.exit sets a stop on line 52, 57.
- Does Channel Break [for free bot] run in Zeal Terminal?
- Yes
- It compiles in 17 ms and runs 1,000 bars in 53 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
- +4.38%
- $43.81
- Buy and hold
- +102.5%
- same period
- Closed trades
- 85
- 26 won · 59 lost
- Profitable
- 30.6%
- of closed trades
- Profit factor
- 1.11
- gross profit ÷ gross loss
- Max drawdown
- 9.73%
- −$104.91
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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 52, 57. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 30
transp = on line 30, 32. 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.
- 2 strategy calls use the when = argument (line 52, 57). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 85 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 24: highest → ta.highest
- Line 25: highest → ta.highest
- Line 25: lowest → ta.lowest
- Line 25: lowest → ta.lowest
- Line 26: lowest → ta.lowest
5 more edits
- Line 27: highest → ta.highest
- Line 27: lowest → ta.lowest
- Line 27: highest → ta.highest
- Line 30: transp = 50 → color.new(color.blue, 50)
- Line 32: transp = 50 → color.new(color.red, 50)
⋯// © algotradingcc -//@version=4+//@version=5strategy("Channel Break [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.075)⋯// Long&Short Levels-BuyEnter = highest(buyPeriod)+BuyEnter = ta.highest(buyPeriod)-BuyExit = isMiddleExit ? (highest(buyPeriod) + lowest(buyPeriod)) / 2: lowest(buyPeriod)+BuyExit = isMiddleExit ? (ta.highest(buyPeriod) + ta.lowest(buyPeriod)) / 2: ta.lowest(buyPeriod)-SellEnter = lowest(sellPeriod)+SellEnter = ta.lowest(sellPeriod)-SellExit = isMiddleExit ? (highest(sellPeriod) + lowest(sellPeriod)) / 2: highest(sellPeriod)+SellExit = isMiddleExit ? (ta.highest(sellPeriod) + ta.lowest(sellPeriod)) / 2: ta.highest(sellPeriod)// 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 & Stop Loss⋯Same 85 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.int()
- Line 11: input() → input.int()
- Line 13: input() → input.int()
7 more edits
- Line 14: input() → input.int()
- Line 15: input() → input.int()
- Line 18: input() → input.int()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 52: when = strategy.position_size > 0 → if block
- Line 57: when = strategy.position_size < 0 → if block
⋯//Options-buyPeriod = input(13, "Channel Period for Long position")+buyPeriod = input.int(13, "Channel Period for Long position")-sellPeriod = input(18, "Channel Period for Short position")+sellPeriod = input.int(18, "Channel Period for Short position")-isMiddleExit = input(true, "Is exit on Base Line?")+isMiddleExit = input.bool(true, "Is exit on Base Line?")-takeProfit = input(46, "Take Profit (%) for position")+takeProfit = input.int(46, "Take Profit (%) for position")-stopLoss = input(9, "Stop Loss (%) for position")+stopLoss = input.int(9, "Stop Loss (%) for position")// 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)⋯ strategy.entry("Long", strategy.long, stop = BuyEnter)-strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TP, when = strategy.position_size > 0)+if strategy.position_size > 0+ strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TP)// Short Position⋯ -strategy.exit("Short Exit", "Short", stop=SellExit, limit = TP, when = strategy.position_size < 0)+if strategy.position_size < 0+ strategy.exit("Short Exit", "Short", stop=SellExit, limit = TP)// 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: 85 before, 85 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.
⋯// © algotradingcc -//@version=5+//@version=6strategy("Channel Break [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.075)⋯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 position | 13 | int | BuyEnter BuyExit |
| Channel Period for Short position | 18 | int | SellEnter SellExit |
| Is exit on Base Line? | true | bool | BuyExit SellExit |
| Take Profit (%) for position | 46 | int | TP |
| Stop Loss (%) for position | 9 | int | SL |
| 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 position (13)BuyEnter · line 24 - Highest / Lowest (
highest,ta.highestin v5)Channel Period for Long position (13)BuyExit · line 25 - Lowest (
lowest,ta.lowestin v5)Channel Period for Short position (18)SellEnter · line 26 - Highest / Lowest (
highest,ta.highestin v5)Channel Period for Short position (18)SellExit · line 27
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 | timeRange and strategy.position_size <= 0 | On | 51 |
| Exit Long Exit stop and limit | strategy.position_size > 0 | On | 52 |
| Open Short short | timeRange and strategy.position_size >= 0 | On | 55 |
| Exit Short Exit stop and limit | strategy.position_size < 0 | On | 57 |
| Close | time > endTest | On | 60 |
| cancel_all | time > endTest | On | 61 |
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 | +4.4% | +102.5% | 85 | 31% | 1.11 | 9.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.5% | +5.5% | 82 | 28% | 1.13 | 3.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +15.3% | +9.8% | 86 | 36% | 1.30 | 10.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.1% | +8.4% | 86 | 33% | 1.07 | 4.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +5.5% | +16.7% | 80 | 41% | 1.11 | 15.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.4% | +21.5% | 87 | 31% | 1.02 | 5.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +2.4% | +148.3% | 79 | 34% | 1.06 | 12.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.1% | +17.1% | 82 | 34% | 1.09 | 2.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 26 | 23% | $1.14 |
| Sideways market | 46 | 37% | $41.69 |
| Falling market | 13 | 23% | $1.31 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
15.6%
The 95th percentile of the worst drawdown when the same 85 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 6.9% to 15.6%; the tick is what actually happened, 9.0%. Order luck alone moves it this much.
All 85 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Jan 2024 41,823.50 | 27 Jan 2024 41,823.50 | 0 | −$0.30 |
| short | 27 Jan 2024 41,823.50 | 28 Jan 2024 42,120.60 | 1 | −$1.72 |
| long | 28 Jan 2024 42,120.60 | 29 Jan 2024 42,031.10 | 1 | −$0.72 |
| short | 29 Jan 2024 42,031.10 | 30 Jan 2024 43,302.70 | 1 | −$6.33 |
| long | 30 Jan 2024 43,302.70 | 31 Jan 2024 42,941.10 | 1 | −$1.95 |
| short | 31 Jan 2024 42,941.10 | 1 Feb 2024 42,580.00 | 1 | $1.37 |
| long | 1 Feb 2024 42,580.00 | 2 Feb 2024 43,082.90 | 1 | $2.04 |
| short | 2 Feb 2024 43,082.90 | 3 Feb 2024 43,200.00 | 1 | −$0.84 |
| long | 3 Feb 2024 43,200.00 | 4 Feb 2024 43,011.10 | 1 | −$1.16 |
| short | 4 Feb 2024 43,011.10 | 5 Feb 2024 42,582.90 | 1 | $1.68 |
| long | 5 Feb 2024 42,582.90 | 6 Feb 2024 42,708.70 | 1 | $0.29 |
| short | 6 Feb 2024 42,708.70 | 7 Feb 2024 43,099.00 | 1 | −$2.11 |
| long | 7 Feb 2024 43,099.00 | 8 Feb 2024 44,349.60 | 1 | $5.44 |
| short | 8 Feb 2024 44,349.60 | 9 Feb 2024 45,614.30 | 1 | −$5.98 |
| long | 9 Feb 2024 45,614.30 | 10 Feb 2024 47,132.80 | 1 | $6.29 |
| short | 10 Feb 2024 47,132.80 | 11 Feb 2024 48,200.00 | 1 | −$4.81 |
| long | 11 Feb 2024 48,200.00 | 12 Feb 2024 48,300.00 | 1 | $0.11 |
| short | 12 Feb 2024 48,300.00 | 13 Feb 2024 49,917.30 | 1 | −$6.94 |
| long | 13 Feb 2024 50,334.80 | 5 Mar 2024 59,510.00 | 21 | $72.84 |
| long | 8 Mar 2024 69,000.00 | 15 Mar 2024 66,391.00 | 7 | −$8.30 |
| long | 8 Apr 2024 71,769.50 | 9 Apr 2024 68,645.50 | 1 | −$9.43 |
| short | 13 Apr 2024 64,493.10 | 15 Apr 2024 66,729.30 | 2 | −$7.52 |
| short | 17 Apr 2024 60,660.60 | 22 Apr 2024 66,120.00 | 5 | −$18.88 |
| short | 30 Apr 2024 59,600.00 | 3 May 2024 61,892.60 | 3 | −$8.10 |
| long | 15 May 2024 65,500.00 | 29 May 2024 68,290.90 | 14 | $8.25 |
| long | 4 Jun 2024 70,687.60 | 7 Jun 2024 69,214.00 | 3 | −$4.52 |
| short | 11 Jun 2024 66,600.10 | 12 Jun 2024 69,024.00 | 1 | −$7.64 |
| short | 14 Jun 2024 66,051.00 | 1 Jul 2024 63,425.70 | 17 | $7.66 |
| short | 4 Jul 2024 58,402.00 | 10 Jul 2024 59,016.40 | 6 | −$2.42 |
| long | 15 Jul 2024 63,288.80 | 30 Jul 2024 66,659.20 | 15 | $10.40 |
| short | 3 Aug 2024 61,230.00 | 8 Aug 2024 59,540.00 | 5 | $5.31 |
| long | 23 Aug 2024 61,858.00 | 27 Aug 2024 60,539.30 | 4 | −$4.66 |
| short | 4 Sep 2024 57,128.00 | 13 Sep 2024 58,515.50 | 9 | −$5.25 |
| long | 13 Sep 2024 59,809.70 | 1 Oct 2024 62,836.40 | 18 | $20.38 |
| short | 10 Oct 2024 59,828.10 | 11 Oct 2024 62,722.00 | 1 | −$10.30 |
| long | 14 Oct 2024 64,478.20 | 25 Oct 2024 65,784.80 | 11 | $3.83 |
| long | 28 Oct 2024 69,519.50 | 1 Nov 2024 69,440.10 | 4 | −$0.54 |
| long | 6 Nov 2024 73,620.10 | 26 Nov 2024 92,858.00 | 20 | $53.21 |
| long | 5 Dec 2024 99,588.00 | 6 Dec 2024 96,945.60 | 1 | −$6.04 |
| long | 15 Dec 2024 104,088.00 | 19 Dec 2024 100,204.00 | 4 | −$8.31 |
| short | 30 Dec 2024 92,232.50 | 6 Jan 2025 98,363.60 | 7 | −$14.47 |
| long | 6 Jan 2025 99,963.70 | 7 Jan 2025 97,005.20 | 1 | −$13.68 |
| short | 9 Jan 2025 91,530.40 | 14 Jan 2025 95,990.50 | 5 | −$10.41 |
| long | 17 Jan 2025 102,724.00 | 27 Jan 2025 101,967.00 | 10 | −$1.82 |
| short | 2 Feb 2025 96,500.00 | 4 Feb 2025 101,329.00 | 2 | −$10.55 |
| long | 21 Feb 2025 98,826.00 | 22 Feb 2025 96,182.00 | 1 | −$5.72 |
| short | 24 Feb 2025 93,388.10 | 2 Mar 2025 88,866.80 | 6 | $9.46 |
| short | 10 Mar 2025 78,258.50 | 14 Mar 2025 85,301.80 | 4 | −$18.61 |
| long | 24 Mar 2025 87,453.70 | 28 Mar 2025 84,950.00 | 4 | −$6.01 |
| short | 6 Apr 2025 81,211.20 | 9 Apr 2025 81,636.70 | 3 | −$1.34 |
| long | 21 Apr 2025 86,496.40 | 6 May 2025 94,733.70 | 15 | $18.55 |
| long | 8 May 2025 97,895.70 | 29 May 2025 106,990.00 | 21 | $18.43 |
| short | 5 Jun 2025 102,000.00 | 8 Jun 2025 106,176.00 | 3 | −$8.73 |
| short | 22 Jun 2025 100,372.00 | 23 Jun 2025 104,365.00 | 1 | −$8.42 |
| long | 30 Jun 2025 108,529.00 | 7 Jul 2025 107,576.00 | 7 | −$2.08 |
| long | 9 Jul 2025 110,529.00 | 24 Jul 2025 118,756.00 | 15 | $14.69 |
| short | 1 Aug 2025 114,723.00 | 7 Aug 2025 116,084.00 | 6 | −$2.74 |
| long | 11 Aug 2025 119,311.00 | 14 Aug 2025 117,794.00 | 3 | −$2.90 |
| short | 22 Aug 2025 112,016.00 | 5 Sep 2025 112,399.00 | 14 | −$1.00 |
| long | 10 Sep 2025 113,486.00 | 22 Sep 2025 114,333.00 | 12 | $1.21 |
| short | 25 Sep 2025 110,180.00 | 29 Sep 2025 113,260.00 | 4 | −$6.00 |
| long | 1 Oct 2025 117,900.00 | 10 Oct 2025 117,632.00 | 9 | −$0.76 |
| short | 10 Oct 2025 108,620.00 | 12 Oct 2025 114,100.00 | 2 | −$20.27 |
| long | 27 Oct 2025 115,467.00 | 29 Oct 2025 109,964.00 | 2 | −$9.73 |
| short | 4 Nov 2025 103,528.00 | 2 Dec 2025 90,233.00 | 28 | $24.91 |
| long | 3 Dec 2025 93,160.00 | 5 Dec 2025 88,825.00 | 2 | −$9.65 |
| long | 9 Dec 2025 94,150.00 | 14 Dec 2025 89,205.90 | 5 | −$10.75 |
| long | 2 Jan 2026 90,588.20 | 7 Jan 2026 90,722.10 | 5 | −$0.00 |
| long | 13 Jan 2026 94,789.10 | 18 Jan 2026 93,617.70 | 5 | −$2.73 |
| short | 20 Jan 2026 88,379.90 | 23 Feb 2026 67,643.40 | 34 | $45.84 |
| long | 2 Mar 2026 69,988.80 | 3 Mar 2026 66,303.10 | 1 | −$11.13 |
| long | 4 Mar 2026 70,096.00 | 6 Mar 2026 68,280.10 | 2 | −$5.57 |
| long | 16 Mar 2026 74,050.00 | 18 Mar 2026 70,809.20 | 2 | −$9.15 |
| short | 27 Mar 2026 65,822.00 | 6 Apr 2026 69,034.20 | 10 | −$10.09 |
| long | 7 Apr 2026 72,026.10 | 28 Apr 2026 76,397.80 | 21 | $11.74 |
| long | 4 May 2026 79,485.70 | 13 May 2026 79,086.80 | 9 | −$1.31 |
| short | 22 May 2026 76,051.00 | 15 Jun 2026 66,860.80 | 24 | $23.95 |
| short | 24 Jun 2026 59,500.00 | 3 Jul 2026 62,546.20 | 9 | −$10.83 |
| long | 6 Jul 2026 64,275.40 | 17 Jul 2026 63,453.40 | 11 | −$2.90 |
| long | 20 Jul 2026 65,600.00 | 24 Jul 2026 64,390.60 | 4 | −$4.04 |
| long | 19 Aug 2026 65,474.50 | 3 Sep 2026 77,252.90 | 15 | $35.97 |
| short | 11 Sep 2026 76,264.00 | 14 Sep 2026 79,173.30 | 3 | −$8.29 |
| short | 15 Sep 2026 76,046.60 | 18 Sep 2026 78,634.00 | 3 | −$7.37 |
| long | 18 Sep 2026 80,560.00 | 7 Oct 2026 84,891.50 | 19 | $22.29 |
| short | 15 Oct 2026 80,393.60 | 21 Oct 2026 83,399.60 | 6 | −$8.18 |
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 |
|---|---|---|---|---|---|
| Channel Break [for free bot] this page | — | v4 strategy | +4.4% | 85 | 9.7% |
| 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 17 ms | Yes 1,000 bars in 53 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/// Strategy testing and optimisation for free Bitmex trading bot // © algotradingcc //@version=4strategy("Channel Break [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.075)//OptionsbuyPeriod = input(13, "Channel Period for Long position")sellPeriod = input(18, "Channel Period for Short position")isMiddleExit = input(true, "Is exit on Base Line?")takeProfit = input(46, "Take Profit (%) for position")stopLoss = input(9, "Stop Loss (%) for position")// 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(buyPeriod)BuyExit = isMiddleExit ? (highest(buyPeriod) + lowest(buyPeriod)) / 2: lowest(buyPeriod)SellEnter = lowest(sellPeriod)SellExit = isMiddleExit ? (highest(sellPeriod) + lowest(sellPeriod)) / 2: highest(sellPeriod)// 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 Profits & Stop LossTP = 0.0SL = 0.0if strategy.position_size > 0 TP := strategy.position_avg_price*(1 + takeProfit/100) SL := strategy.position_avg_price*(1 - stopLoss/100)if strategy.position_size > 0 and SL > BuyExit BuyExit := SL if strategy.position_size < 0 TP := strategy.position_avg_price*(1 - takeProfit/100) SL := strategy.position_avg_price*(1 + stopLoss/100)if strategy.position_size < 0 and SL < SellExit SellExit := SL // Long Position if timeRange and strategy.position_size <= 0 strategy.entry("Long", strategy.long, stop = BuyEnter)strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TP, when = strategy.position_size > 0)// Short Positionif timeRange and strategy.position_size >= 0 strategy.entry("Short", strategy.short, stop = SellEnter) strategy.exit("Short Exit", "Short", stop=SellExit, limit = TP, when = strategy.position_size < 0)// Close & Cancel when over End of the Testif time > endTest strategy.close_all() strategy.cancel_all()