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
- 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
VerifiedSame 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⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Backtest Start Time | timestamp("01 Apr 2016 13:30 +0000") | time | within_timeframe |
| Define backtest end-time (If false, will test up to most recent candle) | false | bool | within_timeframe |
| Backtest End Time (if checked above) | timestamp("01 May 2021 19:30 +0000") | time | within_timeframe |
| No. of candles to lookback when determining ATR is decreasing | 1 | int | volat_decr |
| [Exit] RSI(14) value considered as overbought | 70 | int | line 80 |
What it calculates
- SMA (
sma,ta.smain v5)BOLL_src, BOLL_lengthSMA20 · line 13 - Stdev (
stdev,ta.stdevin v5)BOLL_src, BOLL_lengthBOLL_sDEV_x2 · line 13 - ATR (
atr,ta.atrin v5)BOLL_lengthATR_x2 · line 21 - EMA (
ema,ta.emain v5)close, 20ema_trend · line 46 - RSI (
rsi,ta.rsiin v5)close, 10rsi_10 · line 55 - RSI (
rsi,ta.rsiin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | volat_decr and rsi_upslope and is_squeezing and strategy.position_size == 0 | On | 67 |
| Close Long | bExit | On | 83 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | Stop loss limit raised | 38 |
| (no title) | alert | BOLL bands are squeezing | 43 |
| (no title) | alert | BOLL bands stopped squeezing | 45 |
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 | +28.2% | +102.5% | 30 | 43% | 1.38 | 14.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2.0% | +5.5% | 38 | 39% | 1.07 | 9.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.5% | +9.8% | 33 | 27% | 0.74 | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.2% | +8.4% | 33 | 33% | 0.79 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 28 | 46% | 1.14 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 30 | 33% | 1.06 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.1% | +148.3% | 29 | 41% | 0.88 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 34 | 38% | 0.94 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 11 | 45% | $16,588.50 |
| Sideways market | 14 | 43% | $11,903.40 |
| Falling market | 5 | 40% | −$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.
All 30 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 Mar 2024 63,990.00 | 14 Apr 2024 63,924.50 | 21 | −$65.50 |
| long | 17 Apr 2024 63,793.40 | 2 May 2024 58,365.00 | 15 | −$5,428.43 |
| long | 3 May 2024 59,060.60 | 15 Jun 2024 66,044.00 | 43 | $6,983.39 |
| long | 16 Jun 2024 66,228.30 | 25 Jun 2024 60,293.30 | 9 | −$5,934.95 |
| long | 14 Jul 2024 59,204.00 | 2 Aug 2024 65,354.00 | 19 | $6,150.01 |
| long | 20 Aug 2024 59,438.50 | 28 Aug 2024 59,415.00 | 8 | −$23.50 |
| long | 30 Aug 2024 59,359.00 | 7 Sep 2024 53,963.00 | 8 | −$5,396.03 |
| long | 20 Sep 2024 62,948.00 | 2 Oct 2024 60,804.90 | 12 | −$2,143.08 |
| long | 4 Oct 2024 60,752.70 | 21 Oct 2024 69,032.00 | 17 | $8,279.28 |
| long | 8 Dec 2024 99,832.00 | 18 Dec 2024 106,134.00 | 10 | $6,301.75 |
| long | 26 Dec 2024 99,429.60 | 14 Jan 2025 94,536.10 | 19 | −$4,893.50 |
| long | 15 Jan 2025 96,560.90 | 4 Feb 2025 101,329.00 | 20 | $4,767.66 |
| long | 10 Feb 2025 96,462.80 | 26 Feb 2025 88,680.40 | 16 | −$7,782.36 |
| long | 15 Mar 2025 83,983.20 | 7 Apr 2025 78,430.00 | 23 | −$5,553.19 |
| long | 13 Apr 2025 85,276.90 | 3 May 2025 96,887.10 | 20 | $11,610.20 |
| long | 1 Jun 2025 104,592.00 | 21 Jun 2025 103,298.00 | 20 | −$1,293.90 |
| long | 25 Jun 2025 106,083.00 | 11 Jul 2025 116,010.00 | 16 | $9,927.01 |
| long | 28 Jul 2025 119,416.00 | 3 Aug 2025 112,546.00 | 6 | −$6,869.21 |
| long | 5 Aug 2025 115,055.00 | 20 Aug 2025 112,873.00 | 15 | −$2,182.08 |
| long | 21 Aug 2025 114,271.00 | 30 Aug 2025 108,377.00 | 9 | −$5,893.83 |
| long | 8 Sep 2025 111,137.00 | 25 Sep 2025 113,307.00 | 17 | $2,169.66 |
| long | 27 Sep 2025 109,643.00 | 6 Oct 2025 123,482.00 | 9 | $13,838.90 |
| long | 1 Nov 2025 109,608.00 | 5 Nov 2025 101,497.00 | 4 | −$8,110.78 |
| long | 4 Dec 2025 93,429.90 | 15 Jan 2026 96,951.80 | 42 | $3,521.83 |
| long | 23 Jan 2026 89,559.70 | 30 Jan 2026 84,650.20 | 7 | −$4,909.52 |
| long | 11 Mar 2026 69,948.60 | 28 Mar 2026 66,407.30 | 17 | −$3,541.36 |
| long | 31 Mar 2026 66,797.40 | 19 May 2026 77,001.90 | 49 | $10,204.50 |
| long | 21 May 2026 77,552.20 | 29 May 2026 73,617.50 | 8 | −$3,934.72 |
| long | 30 Jun 2026 60,260.20 | 20 Aug 2026 69,334.80 | 51 | $9,074.58 |
| long | 13 Sep 2026 77,278.70 | 22 Sep 2026 86,620.00 | 9 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| [KL] Bollinger bands + RSI Strategy this page | — | v4 strategy | +28.2% | 30 | 14.7% |
| [KL] Bollinger Bands Consolidation Strategy by DojiEmoji | sma stdev atr ema rsi | v4 strategy | +39.1% | 33 | 19.6% |
| Full strategy AllinOne with risk management MACD RSI PSAR ATR MA by SoftKill21 | rsi sma stdev ema atr | v4 strategy | +2,985,110.0% | 3 | 2,350,820.0% |
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi sma atr | v4 strategy | −42.3% | 18 | 44.8% |
| Take Profit On Trend (by BHD_Trade_Bot) by BHD_Trade_Bot | ema rsi stdev sma | v4 strategy | +54.8% | 9 | 13.1% |
| Atrend by OTS by prim722 | ema rsi sma atr | v4 strategy | +12.1% | 76 | 34.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 26 ms | Yes 1,000 bars in 59 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/// © 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)