Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (11)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,046$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
+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

Verified

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

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Channel Period for Long position13intBuyEnter BuyExit
Channel Period for Short position18intSellEnter SellExit
Is exit on Base Line?trueboolBuyExit SellExit
Take Profit (%) for position46intTP
Stop Loss (%) for position9intSL
Test Start Year2005intstartTest
Test Start Month1intstartTest
Test Start Day1intstartTest
Test End Year2050intendTest
Test End Month12intendTest
Test End Day30intendTest

What it calculates

  • Highest (highest, ta.highest in v5)Channel Period for Long position (13)BuyEnter · line 24
  • Highest / Lowest (highest, ta.highest in v5)Channel Period for Long position (13)BuyExit · line 25
  • Lowest (lowest, ta.lowest in v5)Channel Period for Short position (18)SellEnter · line 26
  • Highest / Lowest (highest, ta.highest in 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.

buyPeriodChannel Period for Long…setting · 13sellPeriodChannel Period for Shor…setting · 18startYearTest Start Yearsetting · 2005startMonthTest Start Monthsetting · 1startDayTest Start Daysetting · 1endYearTest End Yearsetting · 2050endMonthTest End Monthsetting · 12endDayTest End Daysetting · 30timetimeprice datatakeProfitTake Profit (%) for pos…setting · 46stopLossStop Loss (%) for posit…setting · 9BuyEnterHighest→ BuyEnterBuyExitHighest / Lowest→ BuyExitSellEnterLowest→ SellEnterSellExitHighest / Lowest→ SellExitstartTeststartTestvalueendTestendTestvaluetimeRangetimeRangevalueTPTPvalueSLSLvalueentry:LongOpen Longstrategy.entryexit:Long Exitexit Long Exitstrategy.exitentry:ShortOpen Shortstrategy.entryexit:Short Exitexit Short Exitstrategy.exitclose_all:close_all strategy.close_allcancel_all:cancel_all strategy.cancel_allplot:29Buy Enterplotplot:30Buy Exitplotplot:31Sell Enterplotplot:32Sell Exitplot

Order rules

OrderFires whenBy defaultLine
Open Long longtimeRange and strategy.position_size <= 0On51
Exit Long Exit stop and limitstrategy.position_size > 0On52
Open Short shorttimeRange and strategy.position_size >= 0On55
Exit Short Exit stop and limitstrategy.position_size < 0On57
Close time > endTestOn60
cancel_all time > endTestOn61

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.

18/18trades 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+4.4%+102.5%8531%1.119.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.5%+5.5%8228%1.133.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+15.3%+9.8%8636%1.3010.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+1.1%+8.4%8633%1.074.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+5.5%+16.7%8041%1.1115.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.4%+21.5%8731%1.025.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2.4%+148.3%7934%1.0612.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.1%+17.1%8234%1.092.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 market2623%$1.14
Sideways market4637%$41.69
Falling market1323%$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.

0%18%
All 85 trades
SideEntryExitBarsP&L
long27 Jan 2024 41,823.5027 Jan 2024 41,823.500−$0.30
short27 Jan 2024 41,823.5028 Jan 2024 42,120.601−$1.72
long28 Jan 2024 42,120.6029 Jan 2024 42,031.101−$0.72
short29 Jan 2024 42,031.1030 Jan 2024 43,302.701−$6.33
long30 Jan 2024 43,302.7031 Jan 2024 42,941.101−$1.95
short31 Jan 2024 42,941.101 Feb 2024 42,580.001$1.37
long1 Feb 2024 42,580.002 Feb 2024 43,082.901$2.04
short2 Feb 2024 43,082.903 Feb 2024 43,200.001−$0.84
long3 Feb 2024 43,200.004 Feb 2024 43,011.101−$1.16
short4 Feb 2024 43,011.105 Feb 2024 42,582.901$1.68
long5 Feb 2024 42,582.906 Feb 2024 42,708.701$0.29
short6 Feb 2024 42,708.707 Feb 2024 43,099.001−$2.11
long7 Feb 2024 43,099.008 Feb 2024 44,349.601$5.44
short8 Feb 2024 44,349.609 Feb 2024 45,614.301−$5.98
long9 Feb 2024 45,614.3010 Feb 2024 47,132.801$6.29
short10 Feb 2024 47,132.8011 Feb 2024 48,200.001−$4.81
long11 Feb 2024 48,200.0012 Feb 2024 48,300.001$0.11
short12 Feb 2024 48,300.0013 Feb 2024 49,917.301−$6.94
long13 Feb 2024 50,334.805 Mar 2024 59,510.0021$72.84
long8 Mar 2024 69,000.0015 Mar 2024 66,391.007−$8.30
long8 Apr 2024 71,769.509 Apr 2024 68,645.501−$9.43
short13 Apr 2024 64,493.1015 Apr 2024 66,729.302−$7.52
short17 Apr 2024 60,660.6022 Apr 2024 66,120.005−$18.88
short30 Apr 2024 59,600.003 May 2024 61,892.603−$8.10
long15 May 2024 65,500.0029 May 2024 68,290.9014$8.25
long4 Jun 2024 70,687.607 Jun 2024 69,214.003−$4.52
short11 Jun 2024 66,600.1012 Jun 2024 69,024.001−$7.64
short14 Jun 2024 66,051.001 Jul 2024 63,425.7017$7.66
short4 Jul 2024 58,402.0010 Jul 2024 59,016.406−$2.42
long15 Jul 2024 63,288.8030 Jul 2024 66,659.2015$10.40
short3 Aug 2024 61,230.008 Aug 2024 59,540.005$5.31
long23 Aug 2024 61,858.0027 Aug 2024 60,539.304−$4.66
short4 Sep 2024 57,128.0013 Sep 2024 58,515.509−$5.25
long13 Sep 2024 59,809.701 Oct 2024 62,836.4018$20.38
short10 Oct 2024 59,828.1011 Oct 2024 62,722.001−$10.30
long14 Oct 2024 64,478.2025 Oct 2024 65,784.8011$3.83
long28 Oct 2024 69,519.501 Nov 2024 69,440.104−$0.54
long6 Nov 2024 73,620.1026 Nov 2024 92,858.0020$53.21
long5 Dec 2024 99,588.006 Dec 2024 96,945.601−$6.04
long15 Dec 2024 104,088.0019 Dec 2024 100,204.004−$8.31
short30 Dec 2024 92,232.506 Jan 2025 98,363.607−$14.47
long6 Jan 2025 99,963.707 Jan 2025 97,005.201−$13.68
short9 Jan 2025 91,530.4014 Jan 2025 95,990.505−$10.41
long17 Jan 2025 102,724.0027 Jan 2025 101,967.0010−$1.82
short2 Feb 2025 96,500.004 Feb 2025 101,329.002−$10.55
long21 Feb 2025 98,826.0022 Feb 2025 96,182.001−$5.72
short24 Feb 2025 93,388.102 Mar 2025 88,866.806$9.46
short10 Mar 2025 78,258.5014 Mar 2025 85,301.804−$18.61
long24 Mar 2025 87,453.7028 Mar 2025 84,950.004−$6.01
short6 Apr 2025 81,211.209 Apr 2025 81,636.703−$1.34
long21 Apr 2025 86,496.406 May 2025 94,733.7015$18.55
long8 May 2025 97,895.7029 May 2025 106,990.0021$18.43
short5 Jun 2025 102,000.008 Jun 2025 106,176.003−$8.73
short22 Jun 2025 100,372.0023 Jun 2025 104,365.001−$8.42
long30 Jun 2025 108,529.007 Jul 2025 107,576.007−$2.08
long9 Jul 2025 110,529.0024 Jul 2025 118,756.0015$14.69
short1 Aug 2025 114,723.007 Aug 2025 116,084.006−$2.74
long11 Aug 2025 119,311.0014 Aug 2025 117,794.003−$2.90
short22 Aug 2025 112,016.005 Sep 2025 112,399.0014−$1.00
long10 Sep 2025 113,486.0022 Sep 2025 114,333.0012$1.21
short25 Sep 2025 110,180.0029 Sep 2025 113,260.004−$6.00
long1 Oct 2025 117,900.0010 Oct 2025 117,632.009−$0.76
short10 Oct 2025 108,620.0012 Oct 2025 114,100.002−$20.27
long27 Oct 2025 115,467.0029 Oct 2025 109,964.002−$9.73
short4 Nov 2025 103,528.002 Dec 2025 90,233.0028$24.91
long3 Dec 2025 93,160.005 Dec 2025 88,825.002−$9.65
long9 Dec 2025 94,150.0014 Dec 2025 89,205.905−$10.75
long2 Jan 2026 90,588.207 Jan 2026 90,722.105−$0.00
long13 Jan 2026 94,789.1018 Jan 2026 93,617.705−$2.73
short20 Jan 2026 88,379.9023 Feb 2026 67,643.4034$45.84
long2 Mar 2026 69,988.803 Mar 2026 66,303.101−$11.13
long4 Mar 2026 70,096.006 Mar 2026 68,280.102−$5.57
long16 Mar 2026 74,050.0018 Mar 2026 70,809.202−$9.15
short27 Mar 2026 65,822.006 Apr 2026 69,034.2010−$10.09
long7 Apr 2026 72,026.1028 Apr 2026 76,397.8021$11.74
long4 May 2026 79,485.7013 May 2026 79,086.809−$1.31
short22 May 2026 76,051.0015 Jun 2026 66,860.8024$23.95
short24 Jun 2026 59,500.003 Jul 2026 62,546.209−$10.83
long6 Jul 2026 64,275.4017 Jul 2026 63,453.4011−$2.90
long20 Jul 2026 65,600.0024 Jul 2026 64,390.604−$4.04
long19 Aug 2026 65,474.503 Sep 2026 77,252.9015$35.97
short11 Sep 2026 76,264.0014 Sep 2026 79,173.303−$8.29
short15 Sep 2026 76,046.6018 Sep 2026 78,634.003−$7.37
long18 Sep 2026 80,560.007 Oct 2026 84,891.5019$22.29
short15 Oct 2026 80,393.6021 Oct 2026 83,399.606−$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.

ScriptSharesTypeNetTradesMax drawdown
Channel Break [for free bot] this page—v4 strategy+4.4%859.7%
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 17 msYes 1,000 bars in 53 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/// 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()