Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

EMA Bounce Strategy

A Pine Script v4 strategy built on Lowest (10), Highest (10) and Valuewhen (bought, LL). It has 10 order rules, 8 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.04 commission. 10 settings; defaults include Strategy Direction 0, EMA Length 20 and Swing Point Loopback 10.

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 EMA Bounce Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 16 of 16 trades.
How did EMA Bounce Strategy do on BTCUSDT 1D with default settings?
−48.84%
From 26 Jan 2024 to 21 Oct 2026, over 48 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can EMA Bounce 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.
Does EMA Bounce Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 71, 72.
Does EMA Bounce Strategy run in Zeal Terminal?
Yes
It compiles in 22 ms and runs 1,000 bars in 63 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • SL
  • SSL
  • TP
  • STP
  • Bullish Setup
  • Bearish Setup
  • 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 (10)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$5,117$20,253Equity from $10,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
−48.84%
−$4,883.71
Buy and hold
+102.5%
same period
Closed trades
48
20 won · 28 lost
Profitable
41.7%
of closed trades
Profit factor
0.59
gross profit ÷ gross loss
Max drawdown
56.60%
−$5,923.85

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. 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

    2 settings do nothing

    “-----------------Strategy Inputs-------------------”, “-----------------General Inputs-------------------” are declared but never read.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    Uses an argument v6 removed

    when = on line 55, 56, 58, 59, 62, 63, 65, 66, 71, 72. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 79

    transp = on line 79, 81. 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 lowest → ta.lowest, highest → ta.highest, valuewhen → ta.valuewhen, ema → ta.ema.
  • 10 strategy calls use the when = argument (line 55, 56, 58, 59, 62, 63, 65, 66, 71, 72). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 6: //@version=4 → //@version=5
  • Line 14: input(type = input.integer) → input.int()
  • Line 30: lowest → ta.lowest
  • Line 31: highest → ta.highest
  • Line 32: valuewhen → ta.valuewhen
  • Line 33: valuewhen → ta.valuewhen
3 more edits
  • Line 39: ema → ta.ema
  • Line 79: transp = 80 → color.new(color.green, 80)
  • Line 81: transp = 80 → color.new(color.red, 80)
⋯// high above the EMA, then it's a Bear Bounce. This logic can be reverted.-//@version=4+//@version=5strategy("EMA Bounce", overlay=true, ⋯     slippage=0)-direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)+direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))⋯// Price Action Stop and Take Profit-LL=(lowest(i_SPL))*(1-i_PercIncrement)+LL=(ta.lowest(i_SPL))*(1-i_PercIncrement)-HH=(highest(i_SPL))*(1+i_PercIncrement)+HH=(ta.highest(i_SPL))*(1+i_PercIncrement)-LL_price = valuewhen(bought, LL, 0)+LL_price = ta.valuewhen(bought, LL, 0)-HH_price = valuewhen(bought, HH, 0)+HH_price = ta.valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na ⋯/////////////////////// STRATEGY LOGIC /////////////////////////////////////////-EMA=ema(close, i_EMA)+EMA=ta.ema(close, i_EMA)LowAboveEMA=low > EMA⋯plotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, - color=color.green, title="Bullish Setup", transp=80, size=size.auto)+ color=color.new(color.green, 80), title="Bullish Setup", size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, - color=color.red, title="Bearish Setup", transp=80, size=size.auto)+ color=color.new(color.red, 80), title="Bearish Setup", size=size.auto)

Clean v5

VerifiedDownload the v5 script

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

  • Line 17: input() → input.bool()
  • Line 18: input() → input.int()
  • Line 20: input() → input.bool()
  • Line 22: input() → input.bool()
  • Line 23: input() → input.int()
  • Line 24: input() → input.float()
13 more edits
  • Line 25: input() → input.float()
  • Line 50: input() → input.bool()
  • Line 51: input() → input.bool()
  • Line 55: when = SELL and strategy.position_size == 0 → if block
  • Line 56: when = BUY and strategy.position_size == 0 → if block
  • Line 58: when = SELL → if block
  • Line 59: when = BUY → if block
  • Line 62: when = BUY and strategy.position_size == 0 → if block
  • Line 63: when = SELL and strategy.position_size == 0 → if block
  • Line 65: when = BUY → if block
  • Line 66: when = SELL → if block
  • Line 71: when = i_SL → if block
  • Line 72: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------")  +title1=input.bool(true, "-----------------Strategy Inputs-------------------")  -i_EMA=input(20, title="EMA Length")+i_EMA=input.int(20, title="EMA Length")/////////////////////// BACKTESTER /////////////////////////////////////////////-title2=input(true, "-----------------General Inputs-------------------")  +title2=input.bool(true, "-----------------General Inputs-------------------")  // Backtester General Inputs-i_SL=input(true, title="Use Swing Stop Loss and Take Profit")+i_SL=input.bool(true, title="Use Swing Stop Loss and Take Profit")-i_SPL=input(defval=10, title="Swing Point Loopback")+i_SPL=input.int(defval=10, title="Swing Point Loopback")-i_PercIncrement=input(defval=.2, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.float(defval=.2, step=.1, title="Swing Point SL Perc Increment")*0.01-i_TPRRR = input(1.2, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.float(1.2, step=.1, title="Take Profit Risk Reward Ratio")// Bought and Sold Boolean Signal⋯//Inputs-DPR=input(false, "Allow Direct Position Reverse")+DPR=input.bool(false, "Allow Direct Position Reverse")-reverse=input(false, "Reverse Trades")+reverse=input.bool(false, "Reverse Trades")// Entries⋯    if not DPR-        strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)+        if SELL and strategy.position_size == 0+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)+        if BUY and strategy.position_size == 0+            strategy.entry("short", strategy.short)    else     -        strategy.entry("long", strategy.long, when=SELL)+        if SELL+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=BUY)+        if BUY+            strategy.entry("short", strategy.short)else    if not DPR -        strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)+        if BUY and strategy.position_size == 0+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)+        if SELL and strategy.position_size == 0+            strategy.entry("short", strategy.short)    else-        strategy.entry("long", strategy.long, when=BUY)+        if BUY+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=SELL)+        if SELL+            strategy.entry("short", strategy.short)SL=entry_LL_price⋯STP=stp-strategy.exit("TP & SL", "long", limit=TP, stop=SL, when=i_SL)+if i_SL+    strategy.exit("TP & SL", "long", limit=TP, stop=SL)-strategy.exit("TP & SL", "short", limit=STP, stop=SSL, when=i_SL)+if i_SL+    strategy.exit("TP & SL", "short", limit=STP, stop=SSL)/////////////////////// PLOTS //////////////////////////////////////////////////⋯

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: 48 before, 69 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.

⋯// high above the EMA, then it's a Bear Bounce. This logic can be reverted.-//@version=5+//@version=6strategy("EMA Bounce", overlay=true, ⋯

Settings

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

SettingDefaultType and rangeFeeds
Strategy Direction0int (written input.integer) · min -1 · max 1line 15
-----------------Strategy Inputs-------------------trueboolunused
EMA Length20intEMA
-----------------General Inputs-------------------trueboolunused
Use Swing Stop Loss and Take Profittrueboolexit TP & SL
Swing Point Loopback10intLL HH
Swing Point SL Perc Increment.2float · step .1LL HH
Take Profit Risk Reward Ratio1.2float · step .1tp stp
Allow Direct Position Reversefalseboolentry long entry short entry long entry short entry long entry short entry long entry short line 54 line 61
Reverse Tradesfalseboolline 53

What it calculates

  • Lowest (lowest, ta.lowest in v5)Swing Point Loopback (10)LL · line 30
  • Highest (highest, ta.highest in v5)Swing Point Loopback (10)HH · line 31
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, LL, 0LL_price · line 32
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, HH, 0HH_price · line 33
  • EMA (ema, ta.ema in v5)close, EMA Length (20)EMA · line 39

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.

i_SPLSwing Point Loopbacksetting · 10i_PercIncrementSwing Point SL Perc Inc…setting · .2closecloseprice datai_EMAEMA Lengthsetting · 20i_TPRRRTake Profit Risk Reward…setting · 1.2lowlowprice datahighhighprice dataLLLowest→ LLHHHighest→ HHLL_priceValuewhen→ LL_priceHH_priceValuewhen→ HH_priceEMAEMA→ EMAentry_LL_priceentry_LL_pricevalueentry_HH_priceentry_HH_pricevaluetptpvaluestpstpvalueBUYBUYvalueSELLSELLvalueSLSLvalueSSLSSLvalueTPTPvalueSTPSTPvalueboughtboughtconditionLowAboveEMA, LowBelowEMALowAboveEMA · LowBelowE…2 conditionsHighAboveEMA, HighBelowEMAHighAboveEMA · HighBelo…2 conditionsBullBounceBullBounceconditionBearBounceBearBounceconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryexit:TP & SLexit TP & SLstrategy.exitplot:46plotplotplot:74SLplotplot:75SSLplotplot:76TPplotplot:77STPplotplotshape:79Bullish Setupplotshapeplotshape:81Bearish Setupplotshape

Order rules

OrderFires whenBy defaultLine
Open long longSELL and strategy.position_size == 0On55
Open short shortBUY and strategy.position_size == 0On56
Open long longSELLOn58
Open short shortBUYOn59
Open long longBUY and strategy.position_size == 0On62
Open short shortSELL and strategy.position_size == 0On63
Open long longBUYOn65
Open short shortSELLOn66
Exit TP & SL stop and limiti_SLOn71
Exit TP & SL stop and limiti_SLOn72

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.

16/16trades 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−48.8%+102.5%4842%0.5956.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+4.1%+5.5%3441%1.1111.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.8%+9.8%3148%1.0151.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+14.7%+8.4%3853%1.2823.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−15.9%+16.7%3447%0.9152.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.1%+21.5%3741%1.0024.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+37.6%+148.3%4060%1.1931.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−11.2%+17.1%3839%0.7220.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 market1436%−$2,115.29
Sideways market2348%−$1,363.55
Falling market1136%−$1,404.86

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

How bad could the drawdown be?

64.7%

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

0%74%
All 48 trades
SideEntryExitBarsP&L
long17 Mar 2024 65,300.6018 Mar 2024 68,393.501$465.25
long10 Apr 2024 69,146.0013 Apr 2024 64,364.103−$731.53
short1 May 2024 60,672.0017 May 2024 67,366.8016−$1,081.84
long31 May 2024 68,352.204 Jun 2024 70,959.304$322.83
long8 Jun 2024 69,355.6011 Jun 2024 66,536.703−$371.66
short2 Jul 2024 62,900.003 Jul 2024 60,799.901$280.35
short14 Jul 2024 59,204.0015 Jul 2024 61,543.501−$358.14
long26 Jul 2024 65,799.9027 Jul 2024 69,025.501$410.76
short12 Aug 2024 58,712.6023 Aug 2024 62,870.6011−$640.00
short30 Aug 2024 59,359.0026 Sep 2024 65,130.0027−$813.19
short5 Oct 2024 62,086.0015 Oct 2024 66,631.0010−$553.76
long24 Oct 2024 66,668.6028 Oct 2024 69,066.504$243.48
long4 Nov 2024 68,776.006 Nov 2024 71,738.802$303.00
long6 Dec 2024 96,945.6015 Dec 2024 104,898.009$606.71
short22 Dec 2024 97,292.0020 Jan 2025 108,570.0029−$943.33
long28 Jan 2025 102,083.002 Feb 2025 97,582.205−$320.20
short8 Feb 2025 96,506.8026 Feb 2025 84,310.5018$856.28
short7 Mar 2025 89,931.909 Mar 2025 83,622.102$532.35
long28 Mar 2025 87,232.0029 Mar 2025 82,382.101−$462.51
short5 Apr 2025 83,889.906 Apr 2025 78,145.301$524.15
short10 Apr 2025 82,615.2022 Apr 2025 88,677.0012−$613.34
long30 May 2025 105,590.0031 May 2025 103,414.001−$163.76
short21 Jun 2025 103,298.002 Jul 2025 109,170.0011−$431.89
long26 Jul 2025 117,614.001 Aug 2025 114,494.006−$192.81
short7 Aug 2025 114,992.0011 Aug 2025 119,512.004−$275.40
long15 Aug 2025 118,295.0019 Aug 2025 113,128.004−$292.94
short4 Sep 2025 111,706.0010 Sep 2025 113,713.006−$118.22
short22 Oct 2025 108,298.0027 Oct 2025 116,196.005−$455.69
long29 Oct 2025 112,898.0030 Oct 2025 106,453.001−$331.14
short12 Nov 2025 103,059.0016 Nov 2025 93,564.004$492.63
short3 Dec 2025 91,277.909 Dec 2025 94,338.306−$202.07
short18 Dec 2025 86,243.205 Jan 2026 94,778.2018−$567.09
long9 Jan 2026 91,100.0013 Jan 2026 95,929.404$266.97
long20 Jan 2026 92,631.0021 Jan 2026 87,720.201−$289.52
short29 Jan 2026 89,300.0030 Jan 2026 84,650.201$261.21
short26 Feb 2026 67,988.0027 Feb 2026 65,419.101$198.09
short10 Mar 2026 68,432.2016 Mar 2026 74,198.106−$472.41
long19 Mar 2026 71,246.6022 Mar 2026 68,254.603−$217.29
short2 Apr 2026 68,113.907 Apr 2026 72,170.105−$293.56
long30 Apr 2026 75,780.001 May 2026 77,109.701$76.48
long14 May 2026 79,313.6015 May 2026 81,090.001$100.28
short26 May 2026 77,322.0027 May 2026 75,599.801$101.95
short16 Jun 2026 66,328.7017 Jun 2026 65,011.101$92.45
short23 Jun 2026 64,020.0024 Jun 2026 59,931.901$311.62
short3 Jul 2026 61,560.004 Jul 2026 63,365.501−$158.29
long7 Jul 2026 64,042.9020 Aug 2026 71,672.9044$602.49
short18 Sep 2026 76,417.0019 Sep 2026 81,562.801−$388.23
short17 Oct 2026 81,615.9021 Oct 2026 84,520.704−$193.22

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
EMA Bounce Strategy this page—v4 strategy−48.8%4856.6%
Modulo Logic + EMA Strat by tweakerIDlowest highest valuewhen emav4 strategy−50.8%1654.7%
Swing Points Breakouts by tweakerIDlowest highest valuewhenv4 strategy+29.9%9252.0%
CC Trend strategy 2- Downtrend Short by CheatCode1ema highest lowestv5 strategyNo trades on this market
TrianglePoint strategy by mohaneehighest lowest emav4 strategy+45.4%11101.9%
Lagged Donchian Channel + EMA by Mysteriownema highest lowestv4 strategy−12.3%412.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 22 msYes 1,000 bars in 63 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/// © tweakerID// Simple strategy that checks for price bounces over an Exponential Moving Average. If the CLOSE of the candle bounces// back from having it's LOW below the EMA, then it's a Bull Bounce. If the CLOSE of the candle bounces down from having it's// high above the EMA, then it's a Bear Bounce. This logic can be reverted.//@version=4strategy("EMA Bounce", overlay=true,      default_qty_type=strategy.percent_of_equity,      default_qty_value=100,      initial_capital=10000,      commission_value=0.04,      calc_on_every_tick=false,      slippage=0)direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))/////////////////////// STRATEGY INPUTS ////////////////////////////////////////title1=input(true, "-----------------Strategy Inputs-------------------")  i_EMA=input(20, title="EMA Length")/////////////////////// BACKTESTER /////////////////////////////////////////////title2=input(true, "-----------------General Inputs-------------------")  // Backtester General Inputsi_SL=input(true, title="Use Swing Stop Loss and Take Profit")i_SPL=input(defval=10, title="Swing Point Loopback")i_PercIncrement=input(defval=.2, step=.1, title="Swing Point SL Perc Increment")*0.01i_TPRRR = input(1.2, step=.1, title="Take Profit Risk Reward Ratio")// Bought and Sold Boolean Signalbought = strategy.position_size > strategy.position_size[1]  or strategy.position_size < strategy.position_size[1]// Price Action Stop and Take ProfitLL=(lowest(i_SPL))*(1-i_PercIncrement)HH=(highest(i_SPL))*(1+i_PercIncrement)LL_price = valuewhen(bought, LL, 0)HH_price = valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na entry_HH_price = strategy.position_size < 0 ? HH_price : na tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRRstp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR/////////////////////// STRATEGY LOGIC /////////////////////////////////////////EMA=ema(close, i_EMA)LowAboveEMA=low > EMALowBelowEMA=low < EMAHighAboveEMA=high > EMAHighBelowEMA=high < EMABullBounce=LowAboveEMA[1] and LowBelowEMA and close > EMA //and close > openBearBounce=HighBelowEMA[1] and HighAboveEMA and close < EMA //and close < openplot(EMA)BUY=BullBounceSELL=BearBounce//InputsDPR=input(false, "Allow Direct Position Reverse")reverse=input(false, "Reverse Trades")// Entriesif reverse    if not DPR        strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)        strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)    else             strategy.entry("long", strategy.long, when=SELL)        strategy.entry("short", strategy.short, when=BUY)else    if not DPR         strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)        strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)    else        strategy.entry("long", strategy.long, when=BUY)        strategy.entry("short", strategy.short, when=SELL)SL=entry_LL_priceSSL=entry_HH_priceTP=tpSTP=stpstrategy.exit("TP & SL", "long", limit=TP, stop=SL, when=i_SL)strategy.exit("TP & SL", "short", limit=STP, stop=SSL, when=i_SL)/////////////////////// PLOTS //////////////////////////////////////////////////plot(strategy.position_size > 0 ? SL : na , title='SL', style=plot.style_cross, color=color.red)plot(strategy.position_size < 0 ? SSL : na , title='SSL', style=plot.style_cross, color=color.red)plot(strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)plot(strategy.position_size < 0 ? STP : na, title='STP', style=plot.style_cross, color=color.green)// Draw price action setup arrowsplotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar,  color=color.green, title="Bullish Setup", transp=80, size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar,  color=color.red, title="Bearish Setup", transp=80, size=size.auto)