Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

SuperTrend Multi Time Frame Long and Short Trading Strategy

A Pine Script v5 strategy built on ATR (22), Highest (close, 22) and Lowest (close, 22). It has 12 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 60% of equity and pays no commission. 18 settings; defaults include Timeframe 1 D, Timeframe 2 W and ATR Period 22.

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 SuperTrend Multi Time Frame Long and Short Trading Strategy repaint?
Yes
At least one pattern in the source can repaint: higher-timeframe data.
How did SuperTrend Multi Time Frame Long and Short Trading Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
Does SuperTrend Multi Time Frame Long and Short Trading Strategy run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C63: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download.
Does SuperTrend Multi Time Frame Long and Short Trading Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 114, 115, 116, 117, 119, 120, 121, 122.
Does SuperTrend Multi Time Frame Long and Short Trading Strategy run in Zeal Terminal?
Yes
It compiles in 80 ms and runs 1,000 bars in 217 ms, in the browser.

BTCUSDT · 1D · default settings

  • Long Stop
  • Long Stop Start
  • Short Stop
  • Short Stop Start
  • Timeframe 1 CE
  • Timeframe 2 CE
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$2,000$4,051Equity from $2,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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. The live re-run is not offered here: the script requests BINANCE:BTCUSDT W, which this page cannot load in your browser.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

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

    1 setting does nothing

    “Show Buy/Sell Labels ?” is declared but never read.

  • Check

    No commission

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

  • Note

    1 setting has no label

    In the settings dialog KeepLastPosition (line 99) shows an empty name. The labels on this page come from the variable names.

  • 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 101, 102, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Timeframe 1Dtimeframece1_plot ce1
Timeframe 2Wtimeframece2_plot ce2
ATR Period22intatr longStop shortStop atr2 longStop2 shortStop2
ATR Multiplier3.0float · step 0.1atr atr2
Show Buy/Sell Labels ?trueboolunused
Use Close Price for Extremums ?trueboollongStop shortStop longStop2 shortStop2
Highlight State ?trueboollongFillColor shortFillColor
What trades should be taken : BOTHstring · options ['LONG', 'SHORT', 'BOTH']line 57 line 60 line 63 entry long entry short
Backtesting Start Timetimestamp('01 Jun 2021 13:30 +0000')timetimeCond
Backtesting End Timetimestamp('30 Sep 2099 19:30 +0000')timetimeCond
Keep Last Position (no label in the script)falseboolexit Exit4
Trades
Stop Loss %5.0float · min 0sl
TP1 %5intexit Exit1 plot
TP2 %10intexit Exit2 plot
TP3 %15intexit Exit3 plot
TP1 Amount %10intQty1
TP2 Amount %15intQty2
TP3 Amount %20intQty3

What it calculates

  • ATRATR Period (22)atr · line 12
  • Highestclose, ATR Period (22)longStop · line 13
  • Lowestclose, ATR Period (22)shortStop · line 16
  • ATRATR Period (22)atr2 · line 36
  • Highestclose, ATR Period (22)longStop2 · line 37
  • Lowestclose, ATR Period (22)shortStop2 · line 40
  • ValuewhenlongCond, close, 0long_entry · line 73
  • ValuewhenshortCond, close, 0short_entry · line 74

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.

The script has 85 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open long longlongCond == true and tradeType != 'SHORT' and timeCondOn101
Open short shortshortCond == true and tradeType != 'LONG' and timeCondOn102
Exit Exit1 stop and limitstrategy.position_size > 0On114
Exit Exit2 stop and limitstrategy.position_size > 0On115
Exit Exit3 stop and limitstrategy.position_size > 0On116
Exit Exit4 stopstrategy.position_size > 0 and KeepLastPosition == falseOn117
Close longlong_exitsellSignal and pos[1] == 1On118
Exit Exit1 stop and limitstrategy.position_size < 0On119
Exit Exit2 stop and limitstrategy.position_size < 0On120
Exit Exit3 stop and limitstrategy.position_size < 0On121
Exit Exit4 stopstrategy.position_size < 0 and KeepLastPosition == falseOn122
Close shortshort_exitbuySignal and pos[1] == -1On123

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

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • CheckHigher-timeframe data4 request.security call(s) use lookahead_on (line 48, 49, 50, 51). Without a [1] offset this reads future bars in history.
  • 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.3%+5.5%10%0.000.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−1.2%+17.1%10%0.001.4%8 May 2026 – 21 Oct 2026

Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.

Backtests are simulations on historical data and are not investment advice.

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
SuperTrend Multi Time Frame Long and Short Trading Strategy this page—v5 strategy0.0%00.0%
Positive Bars - Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−40.3%754.7%
Big Bar Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−56.6%1357.1%
Inside Bar Strategy w- SL by tweakerIDlowest highest valuewhen atrv4 strategy−61.3%2565.0%
Modulo Logic + EMA Strat by tweakerIDlowest highest valuewhen atrv4 strategy−50.8%1654.7%
Delayed RSI Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−40.4%742.2%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 12 strategy calls use the when = argument (line 101, 102, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 5 settings use the untyped input() (line 7, 9, 10, 11, 99). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 7: input() → input.int()
  • Line 9: input() → input.bool()
  • Line 10: input() → input.bool()
  • Line 11: input() → input.bool()
  • Line 99: input() → input.bool()
  • Line 101: when = longCond == true and tradeType != 'SHORT' and timeCond → if block
11 more edits
  • Line 102: when = shortCond == true and tradeType != 'LONG' and timeCond → if block
  • Line 114: when = strategy.position_size > 0 → if block
  • Line 115: when = strategy.position_size > 0 → if block
  • Line 116: when = strategy.position_size > 0 → if block
  • Line 117: when = strategy.position_size > 0 and KeepLastPosition == false → if block
  • Line 118: when = long_exit → if block
  • Line 119: when = strategy.position_size < 0 → if block
  • Line 120: when = strategy.position_size < 0 → if block
  • Line 121: when = strategy.position_size < 0 → if block
  • Line 122: when = strategy.position_size < 0 and KeepLastPosition == false → if block
  • Line 123: when = short_exit → if block
⋯tf2 = input.timeframe('W', title='Timeframe 2')-length = input(title='ATR Period', defval=22)+length = input.int(title='ATR Period', defval=22)mult = input.float(title='ATR Multiplier', step=0.1, defval=3.0)-showLabels = input(title='Show Buy/Sell Labels ?', defval=true)+showLabels = input.bool(title='Show Buy/Sell Labels ?', defval=true)-useClose = input(title='Use Close Price for Extremums ?', defval=true)+useClose = input.bool(title='Use Close Price for Extremums ?', defval=true)-highlightState = input(title='Highlight State ?', defval=true)+highlightState = input.bool(title='Highlight State ?', defval=true)atr = mult * ta.atr(length)⋯timeCond = time > i_startTime and time < i_endTime-KeepLastPosition = input(false)+KeepLastPosition = input.bool(false)// Make sure we are within the bar range, Set up entries and exit conditions-strategy.entry('long', strategy.long, when=longCond == true and tradeType != 'SHORT' and timeCond)+if longCond == true and tradeType != 'SHORT' and timeCond+    strategy.entry('long', strategy.long)-strategy.entry('short', strategy.short, when=shortCond == true and tradeType != 'LONG' and timeCond)+if shortCond == true and tradeType != 'LONG' and timeCond+    strategy.entry('short', strategy.short)var float Qty1 = na⋯    Qty4-strategy.exit('Exit1', qty=Qty1, stop=sl_long, limit=strategy.position_avg_price * (1 + tp1percent), when=strategy.position_size > 0)+if strategy.position_size > 0+    strategy.exit('Exit1', qty=Qty1, stop=sl_long, limit=strategy.position_avg_price * (1 + tp1percent))-strategy.exit('Exit2', qty=Qty2, stop=sl_long, limit=strategy.position_avg_price * (1 + tp2percent), when=strategy.position_size > 0)+if strategy.position_size > 0+    strategy.exit('Exit2', qty=Qty2, stop=sl_long, limit=strategy.position_avg_price * (1 + tp2percent))-strategy.exit('Exit3', qty=Qty3, stop=sl_long, limit=strategy.position_avg_price * (1 + tp3percent), when=strategy.position_size > 0)+if strategy.position_size > 0+    strategy.exit('Exit3', qty=Qty3, stop=sl_long, limit=strategy.position_avg_price * (1 + tp3percent))-strategy.exit('Exit4', qty=Qty4, stop=sl_long, when=strategy.position_size > 0 and KeepLastPosition == false)+if strategy.position_size > 0 and KeepLastPosition == false+    strategy.exit('Exit4', qty=Qty4, stop=sl_long)-strategy.close('long', when=long_exit, comment='CE Exit')+if long_exit+    strategy.close('long', comment='CE Exit')-strategy.exit('Exit1', qty=Qty1, stop=sl_short, limit=strategy.position_avg_price * (1 - tp1percent), when=strategy.position_size < 0)+if strategy.position_size < 0+    strategy.exit('Exit1', qty=Qty1, stop=sl_short, limit=strategy.position_avg_price * (1 - tp1percent))-strategy.exit('Exit2', qty=Qty2, stop=sl_short, limit=strategy.position_avg_price * (1 - tp2percent), when=strategy.position_size < 0)+if strategy.position_size < 0+    strategy.exit('Exit2', qty=Qty2, stop=sl_short, limit=strategy.position_avg_price * (1 - tp2percent))-strategy.exit('Exit3', qty=Qty3, stop=sl_short, limit=strategy.position_avg_price * (1 - tp3percent), when=strategy.position_size < 0)+if strategy.position_size < 0+    strategy.exit('Exit3', qty=Qty3, stop=sl_short, limit=strategy.position_avg_price * (1 - tp3percent))-strategy.exit('Exit4', qty=Qty4, stop=sl_short, when=strategy.position_size < 0 and KeepLastPosition == false)+if strategy.position_size < 0 and KeepLastPosition == false+    strategy.exit('Exit4', qty=Qty4, stop=sl_short)-strategy.close('short', when=short_exit, comment='CE Exit')+if short_exit+    strategy.close('short', comment='CE Exit')plot(strategy.position_size > 0 ? strategy.position_avg_price * (1 + tp1percent) : na, color=color.new(color.green, 0), style=plot.style_linebr)⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C63: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © ranga_trading-//@version=5+//@version=6strategy(title='SuperTrend Multi Time Frame Long and Short Trading Strategy with Take Profit, Stop Loss and in build alerts V01', shorttitle='SuperTrend Multi Time Frame Long and Short Trading Strategy with Take Profit, Stop Loss and in build alerts V01 ', overlay=true, default_qty_value=60, initial_capital=2000, default_qty_type=strategy.percent_of_equity, pyramiding=0, process_orders_on_close=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 80 msWith a workaround 1,000 bars in 217 msNot measured
PineTSNot testedNot testedNot measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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.

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/// © ranga_trading//@version=5strategy(title='SuperTrend Multi Time Frame Long and Short Trading Strategy with Take Profit, Stop Loss and in build alerts V01', shorttitle='SuperTrend Multi Time Frame Long and Short Trading Strategy with Take Profit, Stop Loss and in build alerts V01 ', overlay=true, default_qty_value=60, initial_capital=2000, default_qty_type=strategy.percent_of_equity, pyramiding=0, process_orders_on_close=true)tf1 = input.timeframe('D', title='Timeframe 1')tf2 = input.timeframe('W', title='Timeframe 2')length = input(title='ATR Period', defval=22)mult = input.float(title='ATR Multiplier', step=0.1, defval=3.0)showLabels = input(title='Show Buy/Sell Labels ?', defval=true)useClose = input(title='Use Close Price for Extremums ?', defval=true)highlightState = input(title='Highlight State ?', defval=true)atr = mult * ta.atr(length)longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atrlongStopPrev = nz(longStop[1], longStop)longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atrshortStopPrev = nz(shortStop[1], shortStop)shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStopvar int dir = 1dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dirvar color longColor = color.greenvar color shortColor = color.redlongStopPlot = plot(dir == 1 ? longStop : na, title='Long Stop', style=plot.style_linebr, linewidth=2, color=color.new(longColor, 0))buySignal = dir == 1 and dir[1] == -1plotshape(buySignal ? longStop : na, title='Long Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(longColor, 0))shortStopPlot = plot(dir == 1 ? na : shortStop, title='Short Stop', style=plot.style_linebr, linewidth=2, color=color.new(shortColor, 0))sellSignal = dir == -1 and dir[1] == 1plotshape(sellSignal ? shortStop : na, title='Short Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(shortColor, 0))midPricePlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0, display=display.none, editable=false)longFillColor = highlightState ? dir == 1 ? longColor : na : nashortFillColor = highlightState ? dir == -1 ? shortColor : na : nafill(midPricePlot, longStopPlot, title='Long State Filling', color=longFillColor, transp=90)fill(midPricePlot, shortStopPlot, title='Short State Filling', color=shortFillColor, transp=90)// CE Functionce() =>    atr2 = mult * ta.atr(length)    longStop2 = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr2    longStop2Prev = nz(longStop2[1], longStop2)    longStop2 := close[1] > longStop2Prev ? math.max(longStop2, longStop2Prev) : longStop2    shortStop2 = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atr2    shortStop2Prev = nz(shortStop2[1], shortStop2)    shortStop2 := close[1] < shortStop2Prev ? math.min(shortStop2, shortStop2Prev) : shortStop2    var int dir2 = 1    dir2 := close > shortStop2Prev ? 1 : close < longStop2Prev ? -1 : dir2    ce = dir2 == 1 ? longStop2 : shortStop2    [dir2, ce][side, ce_plot] = ce()ce1_plot = request.security(syminfo.tickerid, tf1, ce_plot[1], barmerge.gaps_off, barmerge.lookahead_on)ce2_plot = request.security(syminfo.tickerid, tf2, ce_plot[1], barmerge.gaps_off, barmerge.lookahead_on)ce1 = request.security(syminfo.tickerid, tf1, side[1], barmerge.gaps_off, barmerge.lookahead_on)ce2 = request.security(syminfo.tickerid, tf2, side[1], barmerge.gaps_off, barmerge.lookahead_on)long = buySignal and ce1 > 0 and ce2 > 0short = sellSignal and ce1 < 0 and ce2 < 0tradeType = input.string('BOTH', title='What trades should be taken : ', options=['LONG', 'SHORT', 'BOTH'])// Position Management Toolspos = 0.0if tradeType == 'BOTH'    pos := long ? 1 : short ? -1 : pos[1]    posif tradeType == 'LONG'    pos := long ? 1 : pos[1]    posif tradeType == 'SHORT'    pos := short ? -1 : pos[1]    poslongCond = long and (pos[1] != 1 or na(pos[1]))shortCond = short and (pos[1] != -1 or na(pos[1]))plot(ce1_plot, title='Timeframe 1 CE', color=ce1 > 0 ? #008000 : #800000, linewidth=2)plot(ce2_plot, title='Timeframe 2 CE', color=ce2 > 0 ? color.green : color.red, linewidth=2)// EXIT FUNCTIONS //i_sl = input.float(5.0, title='Stop Loss %', minval=0, group='Trades')sl = i_sl > 0 ? i_sl / 100 : 99999long_entry = ta.valuewhen(longCond, close, 0)short_entry = ta.valuewhen(shortCond, close, 0)// Simple Stop Loss + 2 Take Profitssl_long = strategy.position_avg_price * (1 - sl)sl_short = strategy.position_avg_price * (1 + sl)// Position Adjustmentlong_sl = low < sl_long and pos[1] == 1short_sl = high > sl_short and pos[1] == -1if long_sl or short_sl    pos := 0    poslong_exit = sellSignal and pos[1] == 1short_exit = buySignal and pos[1] == -1if long_exit or short_exit    pos := 0    postp1percent = input.int(5, title='TP1 %', group='Trades') / 100.0tp2percent = input.int(10, title='TP2 %', group='Trades') / 100.0tp3percent = input.int(15, title='TP3 %', group='Trades') / 100.0tp1amt = input.int(10, title='TP1 Amount %', group='Trades')tp2amt = input.int(15, title='TP2 Amount %', group='Trades')tp3amt = input.int(20, title='TP3 Amount %', group='Trades')//  Strategy Backtest Limiting Algorithmi_startTime = input.time(defval=timestamp('01 Jun 2021 13:30 +0000'), title='Backtesting Start Time')i_endTime = input.time(defval=timestamp('30 Sep 2099 19:30 +0000'), title='Backtesting End Time')timeCond = time > i_startTime and time < i_endTimeKeepLastPosition = input(false)// Make sure we are within the bar range, Set up entries and exit conditionsstrategy.entry('long', strategy.long, when=longCond == true and tradeType != 'SHORT' and timeCond)strategy.entry('short', strategy.short, when=shortCond == true and tradeType != 'LONG' and timeCond)var float Qty1 = navar float Qty2 = navar float Qty3 = navar float Qty4 = naif strategy.position_size == 0    equity_q = (strategy.initial_capital + strategy.netprofit) / close    Qty1 := equity_q * tp1amt / 100.0    Qty2 := equity_q * tp2amt / 100.0    Qty3 := equity_q * tp3amt / 100.0    Qty4 := equity_q - Qty1 - Qty2 - Qty3    Qty4strategy.exit('Exit1', qty=Qty1, stop=sl_long, limit=strategy.position_avg_price * (1 + tp1percent), when=strategy.position_size > 0)strategy.exit('Exit2', qty=Qty2, stop=sl_long, limit=strategy.position_avg_price * (1 + tp2percent), when=strategy.position_size > 0)strategy.exit('Exit3', qty=Qty3, stop=sl_long, limit=strategy.position_avg_price * (1 + tp3percent), when=strategy.position_size > 0)strategy.exit('Exit4', qty=Qty4, stop=sl_long, when=strategy.position_size > 0 and KeepLastPosition == false)strategy.close('long', when=long_exit, comment='CE Exit')strategy.exit('Exit1', qty=Qty1, stop=sl_short, limit=strategy.position_avg_price * (1 - tp1percent), when=strategy.position_size < 0)strategy.exit('Exit2', qty=Qty2, stop=sl_short, limit=strategy.position_avg_price * (1 - tp2percent), when=strategy.position_size < 0)strategy.exit('Exit3', qty=Qty3, stop=sl_short, limit=strategy.position_avg_price * (1 - tp3percent), when=strategy.position_size < 0)strategy.exit('Exit4', qty=Qty4, stop=sl_short, when=strategy.position_size < 0 and KeepLastPosition == false)strategy.close('short', when=short_exit, comment='CE Exit')plot(strategy.position_size > 0 ? strategy.position_avg_price * (1 + tp1percent) : na, color=color.new(color.green, 0), style=plot.style_linebr)plot(strategy.position_size > 0 ? strategy.position_avg_price * (1 + tp2percent) : na, color=color.new(color.green, 0), style=plot.style_linebr)plot(strategy.position_size > 0 ? strategy.position_avg_price * (1 + tp3percent) : na, color=color.new(color.green, 0), style=plot.style_linebr)plot(strategy.position_size > 0 ? sl_long : na, color=color.new(color.red, 0), style=plot.style_linebr)plot(strategy.position_size > 0 ? strategy.position_avg_price : na, color=color.new(color.gray, 0), style=plot.style_linebr)plot(strategy.position_size < 0 ? strategy.position_avg_price * (1 - tp1percent) : na, color=color.new(color.green, 0), style=plot.style_linebr)plot(strategy.position_size < 0 ? strategy.position_avg_price * (1 - tp2percent) : na, color=color.new(color.green, 0), style=plot.style_linebr)plot(strategy.position_size < 0 ? strategy.position_avg_price * (1 - tp3percent) : na, color=color.new(color.green, 0), style=plot.style_linebr)plot(strategy.position_size < 0 ? sl_short : na, color=color.new(color.red, 0), style=plot.style_linebr)plot(strategy.position_size < 0 ? strategy.position_avg_price : na, color=color.new(color.gray, 0), style=plot.style_linebr)