Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[KL] BOLL + MACD Strategy v2 (published)

A Pine Script v4 strategy built on SMA (BOLL_src, BOLL_length), Stdev (BOLL_src, BOLL_length) and EMA (close, MACD_fastLen). It has 5 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. 7 settings; defaults include Risk:[Reward] for exit 3 and ATR multiplier for stop loss 2.

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] BOLL + MACD Strategy v2 (published) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
How did [KL] BOLL + MACD Strategy v2 (published) do on BTCUSDT 1D with default settings?
−32.05%
From 26 Jan 2024 to 21 Oct 2026, over 28 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [KL] BOLL + MACD Strategy v2 (published) 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] BOLL + MACD Strategy v2 (published) have?
1
Price approached lower band.
Does [KL] BOLL + MACD Strategy v2 (published) use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • Basis
  • Upper
  • Lower
  • ATR Buffer
  • 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 (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$69,616$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
−32.05%
−$32,054.40
Buy and hold
+102.5%
same period
Closed trades
28
12 won · 16 lost
Profitable
42.9%
of closed trades
Profit factor
0.66
gross profit ÷ gross loss
Max drawdown
53.99%
−$53,991.20

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 91, 92. 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. 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, ema → ta.ema, atr → ta.atr, max → math.max, abs → math.abs.
  • 2 strategy calls use the when = argument (line 91, 92). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 4: //@version=4 → //@version=5
  • Line 10: sma → ta.sma
  • Line 11: stdev → ta.stdev
  • Line 16: transp = 50 → color.new(color.navy, 50)
  • Line 17: transp = 50 → color.new(color.navy, 50)
  • Line 18: transp = 85 → color.new(#198787, 85)
12 more edits
  • Line 24: ema → ta.ema
  • Line 24: ema → ta.ema
  • Line 25: ema → ta.ema
  • Line 28: input(type = input.time) → input.time()
  • Line 30: input(type = input.time) → input.time()
  • Line 38: atr → ta.atr
  • Line 40: atr → ta.atr
  • Line 45: max → math.max
  • Line 54: atr → ta.atr
  • Line 61: abs → math.abs
  • Line 61: abs → math.abs
  • Line 87: abs → math.abs
⋯// https://www.tradingview.com/script/EyElTlCG-KL-BOLL-MACD-Strategy-v2-published/-//@version=4+//@version=5strategy("[KL] BOLL + MACD Strategy",overlay=true,pyramiding=1)⋯BOLL_mult = 2.0-BOLL_center = sma(BOLL_src, BOLL_length)+BOLL_center = ta.sma(BOLL_src, BOLL_length)-BOLL_dev = BOLL_mult * stdev(BOLL_src, BOLL_length)+BOLL_dev = BOLL_mult * ta.stdev(BOLL_src, BOLL_length)BOLL_upper = BOLL_center + BOLL_dev⋯plot(BOLL_center, "Basis", color=#872323, offset = BOLL_offset)-BOLL_p1 = plot(BOLL_upper, "Upper", color=color.navy, offset = BOLL_offset, transp=50)+BOLL_p1 = plot(BOLL_upper, "Upper", color=color.new(color.navy, 50), offset = BOLL_offset)-BOLL_p2 = plot(BOLL_lower, "Lower", color=color.navy, offset = BOLL_offset, transp=50)+BOLL_p2 = plot(BOLL_lower, "Lower", color=color.new(color.navy, 50), offset = BOLL_offset)-fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)+fill(BOLL_p1, BOLL_p2, title = "Background", color=color.new(#198787, 85))// }⋯MACD_Len = 9-MACD = ema(close, MACD_fastLen) - ema(close, MACD_slowLen)+MACD = ta.ema(close, MACD_fastLen) - ta.ema(close, MACD_slowLen)-aMACD = ema(MACD, MACD_Len)+aMACD = ta.ema(MACD, MACD_Len)MACD_delta = MACD - aMACD// }-backtest_timeframe_start = input(defval = timestamp("01 Nov 2010 13:30 +0000"), title = "Backtest Start Time", type = input.time)+backtest_timeframe_start = input.time(defval = timestamp("01 Nov 2010 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("19 Mar 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)+backtest_timeframe_end = input.time(defval = timestamp("19 Mar 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")EXIT1 = input(false, title="Take profit when Risk:Reward met")⋯ATR_multi = input(2, "ATR multiplier for stop loss")-ATR_buffer = atr(ATR_multi_len) * ATR_multi+ATR_buffer = ta.atr(ATR_multi_len) * ATR_multiplotchar(ATR_buffer, "ATR Buffer", "", location = location.top)-risk_reward_buffer = (atr(ATR_multi_len) * ATR_multi) * REWARD_RATIO+risk_reward_buffer = (ta.atr(ATR_multi_len) * ATR_multi) * REWARD_RATIOreward_met_long = low > entry_price + risk_reward_buffer⋯var stop_loss_price = float(0)-stop_loss_price := max(stop_loss_price, close - trailing_SL_buffer)+stop_loss_price := math.max(stop_loss_price, close - trailing_SL_buffer)// plot TSL line⋯var bTouched = false-if low < BOLL_center - atr(BOLL_length)+if low < BOLL_center - ta.atr(BOLL_length)    alert("Price approached lower band", alert.freq_once_per_bar)⋯if time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)-    expected_MACD_crossing = MACD > MACD[1] and MACD < aMACD and abs(MACD - aMACD) < abs(MACD[1] - aMACD[1])+    expected_MACD_crossing = MACD > MACD[1] and MACD < aMACD and math.abs(MACD - aMACD) < math.abs(MACD[1] - aMACD[1])    buy_condition = bTouched and expected_MACD_crossing⋯    if EXIT1 or EXIT2 and strategy.position_size > 0-        engulfing_bearish = open - close > abs(open[1]-close[1]) and high > high[1] and (open - close)/(high - low) > 0.4+        engulfing_bearish = open - close > math.abs(open[1]-close[1]) and high > high[1] and (open - close)/(high - low) > 0.4        gapped_down = high < low[1] and close < open⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 29: input() → input.bool()
  • Line 31: input() → input.bool()
  • Line 32: input() → input.int()
  • Line 33: input() → input.bool()
  • Line 37: input() → input.int()
  • Line 91: when = (EXIT1 and reward_met_long) → if block
  • Line 92: when = (EXIT2 and engulfing_bearish) → if block
⋯backtest_timeframe_start = input.time(defval = timestamp("01 Nov 2010 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("19 Mar 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")-EXIT1 = input(false, title="Take profit when Risk:Reward met")+EXIT1 = input.bool(false, title="Take profit when Risk:Reward met")-REWARD_RATIO = input(3,title="Risk:[Reward] for exit")+REWARD_RATIO = input.int(3,title="Risk:[Reward] for exit")-EXIT2 = input(false, title="Take profit when candle is bearish")+EXIT2 = input.bool(false, title="Take profit when candle is bearish")// Trailing stop loss {⋯ATR_multi_len = 26-ATR_multi = input(2, "ATR multiplier for stop loss")+ATR_multi = input.int(2, "ATR multiplier for stop loss")ATR_buffer = ta.atr(ATR_multi_len) * ATR_multi⋯        msg = "exit"-        strategy.close("Long", when=(EXIT1 and reward_met_long), comment="risk:reward met")+        if (EXIT1 and reward_met_long)+            strategy.close("Long", comment="risk:reward met")-        strategy.close("Long", when=(EXIT2 and engulfing_bearish), comment="bearish")+        if (EXIT2 and engulfing_bearish)+            strategy.close("Long", comment="bearish")    // CLEAN UP⋯

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: 28 before, 26 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.

⋯// https://www.tradingview.com/script/EyElTlCG-KL-BOLL-MACD-Strategy-v2-published/-//@version=5+//@version=6strategy("[KL] BOLL + MACD 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 Nov 2010 13:30 +0000")timeline 60
Define backtest end-time (If false, will test up to most recent candle)falseboolline 60
Backtest End Time (if checked above)timestamp("19 Mar 2021 19:30 +0000")timeline 60
Take profit when Risk:Reward metfalseboolclose Long close Long line 86
Risk:[Reward] for exit3intrisk_reward_buffer
Take profit when candle is bearishfalseboolclose Long close Long line 86
ATR multiplier for stop loss2intATR_buffer risk_reward_buffer

What it calculates

  • SMA (sma, ta.sma in v5)BOLL_src, BOLL_lengthBOLL_center · line 10
  • Stdev (stdev, ta.stdev in v5)BOLL_src, BOLL_lengthBOLL_dev · line 11
  • EMA (ema, ta.ema in v5)close, MACD_fastLenMACD · line 24
  • EMA (ema, ta.ema in v5)MACD, MACD_LenaMACD · line 25
  • ATR (atr, ta.atr in v5)ATR_multi_lenATR_buffer · line 38
  • ATR (atr, ta.atr in v5)ATR_multi_lenrisk_reward_buffer · line 40

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.

closecloseprice datahigh · low · closehigh · low · closeprice dataATR_multiATR multiplier for stop…setting · 2REWARD_RATIORisk:[Reward] for exitsetting · 3lowlowprice datahighhighprice dataopenopenprice dataBOLL_centerSMA→ BOLL_centerBOLL_devStdev→ BOLL_devMACDEMA→ MACDaMACDEMA→ aMACDATR_bufferATR→ ATR_bufferrisk_reward_bufferATR→ risk_reward_bufferBOLL_src, entry_priceBOLL_src · entry_price2 valuesBOLL_upper, BOLL_lowerBOLL_upper · BOLL_lower2 valuesMACD_deltaMACD_deltavaluetrailing_SL_buffertrailing_SL_buffervaluestop_loss_pricestop_loss_pricevaluebuy_conditionbuy_conditionconditionreward_met_long, take_profit_shortreward_met_long · take_…2 conditionsexpected_MACD_crossingexpected_MACD_crossingconditionengulfing_bearish, gapped_down, is_bearish_candleengulfing_bearish · gap…3 conditionstrail_profit_line_colorColourtrail_profit_line_colorentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:15Basisplotplot:16Upperplotplot:17Lowerplotfill:BackgroundBackgroundfillplotchar:39plotcharplotcharplot:51plotplotalert:55alertalert

Order rules

OrderFires whenBy defaultLine
Open Long longbuy_conditionOn72
Close Longclose > entry_priceOn79
Close Longclose <= entry_priceOn82
Close Long(EXIT1 and reward_met_long)On91
Close Long(EXIT2 and engulfing_bearish)On92

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

Alerts

AlertCallMessageLine
(no title)alertPrice approached lower band55

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

5/5trades 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−32.1%+102.5%2843%0.6654.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+3.4%+5.5%2832%1.1315.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−3.7%+9.8%3030%0.463.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%2733%1.260.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.1%+16.7%2540%0.590.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%2638%1.110.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%2157%1.070.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%2829%1.210.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 market850%−$11,966.10
Sideways market1217%−$54,470.90
Falling market875%$34,382.60

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

How bad could the drawdown be?

62.3%

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

0%72%
All 28 trades
SideEntryExitBarsP&L
long26 Mar 2024 69,880.0014 Apr 2024 63,924.5019−$5,955.48
long21 Apr 2024 64,940.602 May 2024 58,365.0011−$6,575.61
long4 May 2024 62,882.0021 Jun 2024 64,870.0048$1,987.98
long1 Jul 2024 62,772.005 Jul 2024 57,050.004−$5,721.99
long10 Jul 2024 58,050.003 Aug 2024 61,498.3024$3,448.34
long9 Aug 2024 61,686.002 Sep 2024 57,301.8024−$4,384.23
long10 Sep 2024 57,042.0011 Oct 2024 60,326.4031$3,284.39
long12 Oct 2024 62,540.005 Nov 2024 67,850.0024$5,310.02
long3 Jan 2025 96,984.8010 Jan 2025 92,552.507−$4,432.30
long15 Jan 2025 96,560.903 Feb 2025 97,700.6019$1,139.74
long13 Feb 2025 97,870.0026 Feb 2025 88,680.4013−$9,189.61
long3 Mar 2025 94,270.0010 Mar 2025 80,734.507−$13,535.50
long13 Mar 2025 83,680.109 Apr 2025 76,322.4027−$7,357.70
long10 Apr 2025 82,615.206 Jun 2025 101,509.0057$18,893.50
long10 Jun 2025 110,263.0021 Jun 2025 103,298.0011−$6,965.04
long24 Jun 2025 105,334.002 Aug 2025 113,298.0039$7,963.98
long8 Aug 2025 117,472.0016 Aug 2025 117,342.008−$129.98
long23 Aug 2025 116,936.0030 Aug 2025 108,377.007−$8,558.60
long3 Sep 2025 111,240.0026 Sep 2025 108,994.0023−$2,245.52
long29 Sep 2025 112,164.0011 Oct 2025 112,774.0012$610.53
long21 Oct 2025 110,532.004 Nov 2025 106,583.0014−$3,949.04
long10 Nov 2025 104,723.0015 Nov 2025 94,594.005−$10,128.90
long25 Nov 2025 88,300.0021 Jan 2026 88,427.7057$127.65
long10 Feb 2026 70,138.0028 Mar 2026 66,407.3046−$3,730.72
long1 Apr 2026 68,284.5023 May 2026 75,539.5052$7,255.01
long12 Jun 2026 63,626.0025 Jun 2026 61,078.0013−$2,548.00
long5 Aug 2026 64,106.6011 Sep 2026 76,568.7037$12,462.20
long19 Sep 2026 80,883.909 Oct 2026 81,754.5020$870.60

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] BOLL + MACD Strategy v2 (published) this page—v4 strategy−32.1%2854.0%
Trend Following with Bollinger Bands by Robrecht99sma stdev ema atrv5 strategy+2.5%71.7%
[EURUSD60] BB Expansion Strategy by kasaismsma stdev ema atrv4 strategyNo trades on this market
[KL] Bollinger bands + RSI Strategy by DojiEmojisma stdev atr emav4 strategy+28.2%3014.7%
[KL] Bollinger Bands Consolidation Strategy by DojiEmojisma stdev atr emav4 strategy+39.1%3319.6%
Full strategy AllinOne with risk management MACD RSI PSAR ATR MA by SoftKill21sma stdev ema atrv4 strategy+2,985,110.0%32,350,820.0%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 28 msYes 1,000 bars in 45 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// https://www.tradingview.com/script/EyElTlCG-KL-BOLL-MACD-Strategy-v2-published///@version=4strategy("[KL] BOLL + MACD Strategy",overlay=true,pyramiding=1)// BOLL bands {BOLL_length = 20BOLL_src = closeBOLL_mult = 2.0BOLL_center = sma(BOLL_src, BOLL_length)BOLL_dev = BOLL_mult * stdev(BOLL_src, BOLL_length)BOLL_upper = BOLL_center + BOLL_devBOLL_lower = BOLL_center - BOLL_devBOLL_offset = 0plot(BOLL_center, "Basis", color=#872323, offset = BOLL_offset)BOLL_p1 = plot(BOLL_upper, "Upper", color=color.navy, offset = BOLL_offset, transp=50)BOLL_p2 = plot(BOLL_lower, "Lower", color=color.navy, offset = BOLL_offset, transp=50)fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)// }// MACD signals {MACD_fastLen = 12MACD_slowLen = 26MACD_Len = 9MACD = ema(close, MACD_fastLen) - ema(close, MACD_slowLen)aMACD = ema(MACD, MACD_Len)MACD_delta = MACD - aMACD// }backtest_timeframe_start = input(defval = timestamp("01 Nov 2010 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("19 Mar 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)EXIT1 = input(false, title="Take profit when Risk:Reward met")REWARD_RATIO = input(3,title="Risk:[Reward] for exit")EXIT2 = input(false, title="Take profit when candle is bearish")// Trailing stop loss {var entry_price = float(0)ATR_multi_len = 26ATR_multi = input(2, "ATR multiplier for stop loss")ATR_buffer = atr(ATR_multi_len) * ATR_multiplotchar(ATR_buffer, "ATR Buffer", "", location = location.top)risk_reward_buffer = (atr(ATR_multi_len) * ATR_multi) * REWARD_RATIOreward_met_long = low > entry_price + risk_reward_buffertake_profit_short = low < entry_price - risk_reward_buffervar trailing_SL_buffer = float(0)var stop_loss_price = float(0)stop_loss_price := max(stop_loss_price, close - trailing_SL_buffer)// plot TSL linetrail_profit_line_color = color.greenif strategy.position_size == 0  // make TSL line less visible    trail_profit_line_color := color.black    stop_loss_price := close - trailing_SL_bufferplot(stop_loss_price,color=trail_profit_line_color)// }var bTouched = falseif low < BOLL_center - atr(BOLL_length)    alert("Price approached lower band", alert.freq_once_per_bar)    bTouched := trueelse if low > BOLL_center    bTouched := false// MAINif time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)    expected_MACD_crossing = MACD > MACD[1] and MACD < aMACD and abs(MACD - aMACD) < abs(MACD[1] - aMACD[1])    buy_condition = bTouched and expected_MACD_crossing    //ENTRY {    if buy_condition        if strategy.position_size == 0            entry_price := close            trailing_SL_buffer := ATR_buffer            stop_loss_price := close - ATR_buffer        msg = "buy"        if strategy.position_size > 0            msg := "+"        strategy.entry("Long",strategy.long, comment=msg)        // }    //EXIT:     // Case A:    if strategy.position_size > 0 and close <= stop_loss_price        if close > entry_price            strategy.close("Long", comment="take profit [trailing]")            stop_loss_price := 0        else if close <= entry_price            strategy.close("Long", comment="stop loss")            stop_loss_price := 0                // Case B:     if EXIT1 or EXIT2 and strategy.position_size > 0        engulfing_bearish = open - close > abs(open[1]-close[1]) and high > high[1] and (open - close)/(high - low) > 0.4        gapped_down = high < low[1] and close < open        is_bearish_candle = engulfing_bearish or gapped_down        msg = "exit"        strategy.close("Long", when=(EXIT1 and reward_met_long), comment="risk:reward met")        strategy.close("Long", when=(EXIT2 and engulfing_bearish), comment="bearish")    // CLEAN UP    if strategy.position_size == 0        stop_loss_price := 0