Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[KL] Bollinger bands + RSI Strategy

A Pine Script v4 strategy built on SMA (BOLL_src, BOLL_length), Stdev (BOLL_src, BOLL_length) and ATR (BOLL_length). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 5 settings; defaults include No. of candles to lookback when determining ATR is decreasing 1 and [Exit] RSI(14) value considered as overbought 70.

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 [KL] Bollinger bands + RSI Strategy 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 [KL] Bollinger bands + RSI Strategy do on BTCUSDT 1D with default settings?
+28.21%
From 26 Jan 2024 to 21 Oct 2026, over 30 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [KL] Bollinger bands + RSI Strategy 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.
What alerts does [KL] Bollinger bands + RSI Strategy have?
3
Stop loss limit raised; BOLL bands are squeezing; BOLL bands stopped squeezing.
Does [KL] Bollinger bands + RSI Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • Basis
  • BOLL Upper
  • BOLL Lower
  • SMA20 + ATR_x2
  • SMA20 - ATR_x2
  • ATR_x2
  • 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$130,287$202,527Equity from $100,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
+28.21%
$28,214.10
Buy and hold
+102.5%
same period
Closed trades
30
13 won · 17 lost
Profitable
43.3%
of closed trades
Profit factor
1.38
gross profit ÷ gross loss
Max drawdown
14.66%
−$17,090.70

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

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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 83. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 16

    transp = on line 16, 17, 18, 23, 24. 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 sma → ta.sma, stdev → ta.stdev, atr → ta.atr, max → math.max, ema → ta.ema, rsi → ta.rsi.
  • 1 strategy call uses the when = argument (line 83). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 4: //@version=4 → //@version=5
  • Line 7: input(type = input.time) → input.time()
  • Line 9: input(type = input.time) → input.time()
  • Line 13: sma → ta.sma
  • Line 13: stdev → ta.stdev
  • Line 16: transp = 50 → color.new(color.navy, 50)
10 more edits
  • Line 17: transp = 50 → color.new(color.navy, 50)
  • Line 18: transp = 85 → color.new(#198787, 85)
  • Line 21: atr → ta.atr
  • Line 22: sma → ta.sma
  • Line 23: transp = 50 → color.new(color.gray, 50)
  • Line 24: transp = 50 → color.new(color.gray, 50)
  • Line 35: max → math.max
  • Line 46: ema → ta.ema
  • Line 55: rsi → ta.rsi
  • Line 55: rsi → ta.rsi
⋯// -//@version=4+//@version=5strategy("[KL] BOLL + RSI Strategy",overlay=true,pyramiding=1)// Timeframe {-backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)+backtest_timeframe_start = input.time(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time")USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")-backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)+backtest_timeframe_end = input.time(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")within_timeframe = time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)⋯// Bollinger bands (sdv=2, len=20) {-BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)+BOLL_length = 20, BOLL_src = close, SMA20 = ta.sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * ta.stdev(BOLL_src, BOLL_length)BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2plot(SMA20, "Basis", color=#872323, offset = 0)-BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)+BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.new(color.navy, 50), offset = 0)-BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)+BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.new(color.navy, 50), offset = 0)-fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)+fill(BOLL_p1, BOLL_p2, title = "Background", color=color.new(#198787, 85))// }// Volatility Indicators {-ATR_x2 = atr(BOLL_length) * 2 // multiplier aligns with BOLL+ATR_x2 = ta.atr(BOLL_length) * 2 // multiplier aligns with BOLL-avg_atr = sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))+avg_atr = ta.sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))-plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)+plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.new(color.gray, 50), offset = 0)-plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)+plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.new(color.gray, 50), offset = 0)plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)⋯else if strategy.position_size > 0-    stop_loss_price := max(stop_loss_price, TSL_source - ATR_x2)+    stop_loss_price := math.max(stop_loss_price, TSL_source - ATR_x2)plot(stop_loss_price, color=trail_profit_line_color)⋯    alert("BOLL bands stopped squeezing", alert.freq_once_per_bar)-ema_trend = ema(close, 20)+ema_trend = ta.ema(close, 20)concat(a, b) =>⋯// Sell setup - Long position {-rsi_10 = rsi(close, 10), rsi_14 = rsi(close, 14)+rsi_10 = ta.rsi(close, 10), rsi_14 = ta.rsi(close, 14)overbought = rsi_14 > input(70,title="[Exit] RSI(14) value considered as overbought") and rsi_10 > rsi_14⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.bool()
  • Line 22: input() → input.int()
  • Line 56: input() → input.int()
  • Line 83: when = bExit → if block
⋯backtest_timeframe_start = input.time(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time")-USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")+USE_ENDTIME = input.bool(false,title="Define backtest end-time (If false, will test up to most recent candle)")backtest_timeframe_end = input.time(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")⋯ATR_x2 = ta.atr(BOLL_length) * 2 // multiplier aligns with BOLL-avg_atr = ta.sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))+avg_atr = ta.sma(ATR_x2, input.int(1,title="No. of candles to lookback when determining ATR is decreasing"))plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.new(color.gray, 50), offset = 0)⋯rsi_10 = ta.rsi(close, 10), rsi_14 = ta.rsi(close, 14)-overbought = rsi_14 > input(70,title="[Exit] RSI(14) value considered as overbought") and rsi_10 > rsi_14+overbought = rsi_14 > input.int(70,title="[Exit] RSI(14) value considered as overbought") and rsi_10 > rsi_14// } end of Sell setup - Long position⋯            bExit := true-        strategy.close("Long", when=bExit, comment=exit_msg)+        if bExit+            strategy.close("Long", comment=exit_msg)    // }⋯

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: 30 before, 27 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.

⋯// -//@version=5+//@version=6strategy("[KL] BOLL + RSI Strategy",overlay=true,pyramiding=1)⋯

Settings

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

SettingDefaultType and rangeFeeds
Backtest Start Timetimestamp("01 Apr 2016 13:30 +0000")timewithin_timeframe
Define backtest end-time (If false, will test up to most recent candle)falseboolwithin_timeframe
Backtest End Time (if checked above)timestamp("01 May 2021 19:30 +0000")timewithin_timeframe
No. of candles to lookback when determining ATR is decreasing1intvolat_decr
[Exit] RSI(14) value considered as overbought70intline 80

What it calculates

  • SMA (sma, ta.sma in v5)BOLL_src, BOLL_lengthSMA20 · line 13
  • Stdev (stdev, ta.stdev in v5)BOLL_src, BOLL_lengthBOLL_sDEV_x2 · line 13
  • ATR (atr, ta.atr in v5)BOLL_lengthATR_x2 · line 21
  • EMA (ema, ta.ema in v5)close, 20ema_trend · line 46
  • RSI (rsi, ta.rsi in v5)close, 10rsi_10 · line 55
  • RSI (rsi, ta.rsi in v5)close, 14rsi_14 · line 55

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.

high · low · closehigh · low · closeprice dataclosecloseprice datalowlowprice dataavg_atrNo. of candles to lookb…setting · 1timetimeprice databacktest_timeframe_startBacktest Start Timesetting · timestamp("01 Apr 2…backtest_timeframe_endBacktest End Time (if c…setting · timestamp("01 May 2…SMA20SMA→ SMA20BOLL_sDEV_x2Stdev→ BOLL_sDEV_x2ATR_x2ATR→ ATR_x2ema_trendEMA→ ema_trendrsi_10RSI→ rsi_10rsi_14RSI→ rsi_14BOLL_src, entry_priceBOLL_src · entry_price2 valuesBOLL_upper, BOLL_lowerBOLL_upper · BOLL_lower2 valuesTSL_sourceTSL_sourcevaluestop_loss_pricestop_loss_pricevalueconcatconcatvalueexit_msgexit_msgvalueis_squeezingis_squeezingconditionvolat_decrvolat_decrconditionrsi_upslopersi_upslopeconditionwithin_timeframewithin_timeframeconditiontrail_profit_line_colorColourtrail_profit_line_colorentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:15Basisplotplot:16BOLL Upperplotplot:17BOLL Lowerplotfill:BackgroundBackgroundfillplot:23SMA20 + ATR_x2plotplot:24SMA20 - ATR_x2plotplotchar:25plotcharplotcharplot:36plotplotalert:38alertalertalert:43alertalertalert:45alertalert

Order rules

OrderFires whenBy defaultLine
Open Long longvolat_decr and rsi_upslope and is_squeezing and strategy.position_size == 0On67
Close LongbExitOn83

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

Alerts

AlertCallMessageLine
(no title)alertStop loss limit raised38
(no title)alertBOLL bands are squeezing43
(no title)alertBOLL bands stopped squeezing45

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+28.2%+102.5%3043%1.3814.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.0%+5.5%3839%1.079.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.5%+9.8%3327%0.743.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.2%+8.4%3333%0.790.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%2846%1.140.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%3033%1.060.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.1%+148.3%2941%0.880.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%3438%0.940.1%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 market1145%$16,588.50
Sideways market1443%$11,903.40
Falling market540%−$277.74

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

How bad could the drawdown be?

32.5%

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

0%37%
All 30 trades
SideEntryExitBarsP&L
long24 Mar 2024 63,990.0014 Apr 2024 63,924.5021−$65.50
long17 Apr 2024 63,793.402 May 2024 58,365.0015−$5,428.43
long3 May 2024 59,060.6015 Jun 2024 66,044.0043$6,983.39
long16 Jun 2024 66,228.3025 Jun 2024 60,293.309−$5,934.95
long14 Jul 2024 59,204.002 Aug 2024 65,354.0019$6,150.01
long20 Aug 2024 59,438.5028 Aug 2024 59,415.008−$23.50
long30 Aug 2024 59,359.007 Sep 2024 53,963.008−$5,396.03
long20 Sep 2024 62,948.002 Oct 2024 60,804.9012−$2,143.08
long4 Oct 2024 60,752.7021 Oct 2024 69,032.0017$8,279.28
long8 Dec 2024 99,832.0018 Dec 2024 106,134.0010$6,301.75
long26 Dec 2024 99,429.6014 Jan 2025 94,536.1019−$4,893.50
long15 Jan 2025 96,560.904 Feb 2025 101,329.0020$4,767.66
long10 Feb 2025 96,462.8026 Feb 2025 88,680.4016−$7,782.36
long15 Mar 2025 83,983.207 Apr 2025 78,430.0023−$5,553.19
long13 Apr 2025 85,276.903 May 2025 96,887.1020$11,610.20
long1 Jun 2025 104,592.0021 Jun 2025 103,298.0020−$1,293.90
long25 Jun 2025 106,083.0011 Jul 2025 116,010.0016$9,927.01
long28 Jul 2025 119,416.003 Aug 2025 112,546.006−$6,869.21
long5 Aug 2025 115,055.0020 Aug 2025 112,873.0015−$2,182.08
long21 Aug 2025 114,271.0030 Aug 2025 108,377.009−$5,893.83
long8 Sep 2025 111,137.0025 Sep 2025 113,307.0017$2,169.66
long27 Sep 2025 109,643.006 Oct 2025 123,482.009$13,838.90
long1 Nov 2025 109,608.005 Nov 2025 101,497.004−$8,110.78
long4 Dec 2025 93,429.9015 Jan 2026 96,951.8042$3,521.83
long23 Jan 2026 89,559.7030 Jan 2026 84,650.207−$4,909.52
long11 Mar 2026 69,948.6028 Mar 2026 66,407.3017−$3,541.36
long31 Mar 2026 66,797.4019 May 2026 77,001.9049$10,204.50
long21 May 2026 77,552.2029 May 2026 73,617.508−$3,934.72
long30 Jun 2026 60,260.2020 Aug 2026 69,334.8051$9,074.58
long13 Sep 2026 77,278.7022 Sep 2026 86,620.009$9,341.28

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
[KL] Bollinger bands + RSI Strategy this page—v4 strategy+28.2%3014.7%
[KL] Bollinger Bands Consolidation Strategy by DojiEmojisma stdev atr ema rsiv4 strategy+39.1%3319.6%
Full strategy AllinOne with risk management MACD RSI PSAR ATR MA by SoftKill21rsi sma stdev ema atrv4 strategy+2,985,110.0%32,350,820.0%
3 x EMA + Stochastic RSI + ATR by tomimarsonema rsi sma atrv4 strategy−42.3%1844.8%
Take Profit On Trend (by BHD_Trade_Bot) by BHD_Trade_Botema rsi stdev smav4 strategy+54.8%913.1%
Atrend by OTS by prim722ema rsi sma atrv4 strategy+12.1%7634.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 26 msYes 1,000 bars in 59 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/// © DojiEmoji// //@version=4strategy("[KL] BOLL + RSI Strategy",overlay=true,pyramiding=1)// Timeframe {backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)within_timeframe = time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)// }// Bollinger bands (sdv=2, len=20) {BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2plot(SMA20, "Basis", color=#872323, offset = 0)BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)// }// Volatility Indicators {ATR_x2 = atr(BOLL_length) * 2 // multiplier aligns with BOLLavg_atr = sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)//}// Trailing stop loss {TSL_source = lowvar entry_price = float(0), var stop_loss_price = float(0)trail_profit_line_color = color.greenif strategy.position_size == 0 or not within_timeframe    trail_profit_line_color := color.black    stop_loss_price := TSL_source - ATR_x2else if strategy.position_size > 0    stop_loss_price := max(stop_loss_price, TSL_source - ATR_x2)plot(stop_loss_price, color=trail_profit_line_color)if strategy.position_size > 0 and stop_loss_price > stop_loss_price[1]    alert("Stop loss limit raised", alert.freq_once_per_bar)// } end of Trailing stop loss//Buy setup - Long positions {is_squeezing = ATR_x2 > BOLL_sDEV_x2if is_squeezing and within_timeframe and not is_squeezing[1]    alert("BOLL bands are squeezing", alert.freq_once_per_bar)else if not is_squeezing and within_timeframe and is_squeezing[1]    alert("BOLL bands stopped squeezing", alert.freq_once_per_bar)ema_trend = ema(close, 20)concat(a, b) =>    concat = a    if a != ""        concat := concat + ", "    concat := concat + b    concat// }// Sell setup - Long position {rsi_10 = rsi(close, 10), rsi_14 = rsi(close, 14)overbought = rsi_14 > input(70,title="[Exit] RSI(14) value considered as overbought") and rsi_10 > rsi_14// } end of Sell setup - Long position// MAIN: {if within_timeframe    entry_msg = ""    exit_msg = ""    // ENTRY {    conf_count = 0      volat_decr = avg_atr <= avg_atr[1]    rsi_upslope = rsi_10 > rsi_10[1] and rsi_14 > rsi_14[1]    if volat_decr and rsi_upslope and is_squeezing and strategy.position_size == 0        strategy.entry("Long",strategy.long, comment=entry_msg)        entry_price := close        stop_loss_price := TSL_source - ATR_x2    // }    // EXIT {    if strategy.position_size > 0        bExit = false        if close <= entry_price and TSL_source <= stop_loss_price            exit_msg := concat(exit_msg, "stop loss [TSL]")            bExit := true        else if close > entry_price and TSL_source <= stop_loss_price            exit_msg := concat(exit_msg, "take profit [TSL]")            bExit := true        else if overbought            exit_msg := concat(exit_msg, "overbought")            bExit := true        strategy.close("Long", when=bExit, comment=exit_msg)    // }// }// CLEAN UP:if strategy.position_size == 0 and not is_squeezing    entry_price := 0    stop_loss_price := float(0)