Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Ta Strategy

A Pine Script v5 strategy built on Pivothigh (high, 6), Pivotlow (low, 6) and EMA (close, 12). It has 40 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 5% of equity and pays 0.1% commission. 15 settings; defaults include Direction Both, Left Bars 6 and Right Bars 6.

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 Ta Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Ta Strategy do on BTCUSDT 1D with default settings?
+0.26%
From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Ta Strategy 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: 8 before, 0 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Ta Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 53, 54, 57, 60, 61, 64, 68, 69, 72, 76, 77, 80, 85, 86, 89, 92, 93, 96, 100, 101, 104, 108, 109, 112.
Does Ta Strategy run in Zeal Terminal?
Yes
It compiles in 72 ms and runs 1,000 bars in 118 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • res
  • sup
  • 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 (15)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,003$2,025Equity from $1,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
+0.26%
$2.58
Buy and hold
+102.5%
same period
Closed trades
8
3 won · 5 lost
Profitable
37.5%
of closed trades
Profit factor
1.79
gross profit ÷ gross loss
Max drawdown
0.29%
−$2.89

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

  • Note

    1 setting has no label

    In the settings dialog direction (line 7) 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.

Settings

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

SettingDefaultType and rangeFeeds
Inverse StrategyThis option makes you reverse the strategy so that long signals become where to short falseboolline 49
Direction (no label in the script)Bothstring · options ["Both" , "Short" , "Long"]exit exit long 1 exit exit long 2 exit exit short 1 exit exit short 2 exit exit short 3 exit exit long 1 exit exit long 2 exit exit short 1 exit exit short 2 exit exit short 3 exit exit long 1 exit exit long 2 exit exit short 1 exit exit short 2 exit exit short 3 exit exit long 1 exit exit long 2 exit exit short 1 exit exit short 2 exit exit short 3 line 50 line 65 line 73 line 82 line 97 line 105
QTY to sell at TP 150intexit exit long 1 exit exit short 1
Support and resistance
Left Bars6intres sup
Right Bars6intres sup res sup
MACD
MACD Fast12intmacd
MACD Slow26intmacd
MACD Signal7intsignal
ADX
ADX Length14inttruerange plusDI minusDI dx adx
Exit LONG Orders
Long TP 16float · min 0.0 · step 0.25longtakeprofit1
Long TP 212float · min 0.0 · step 0.25longtakeprofit2
Long SL3.0float · min 0.0 · step 0.25longstoploss1
Exit SHORT Orders
Short TP 1 6.0float · min 0.0 · step 0.25shorttakeprofit1
Short TP 212.0float · min 0.0 · step 0.25shorttakeprofit2
Short SL3.0float · min 0.0 · step 0.25shortstoploss1

What it calculates

  • Pivothighhigh, Left Bars (6), Right Bars (6)res · line 16
  • Pivotlowlow, Left Bars (6), Right Bars (6)sup · line 17
  • EMAclose, MACD Fast (12)macd · line 19
  • EMAmacd, MACD Signal (7)signal · line 20
  • Changehighup · line 22
  • Changelowdown · line 23
  • RMAta.tr, ADX Length (14)truerange · line 26
  • RMAplusDM, ADX Length (14)plusDI · line 27
  • RMAminusDM, ADX Length (14)minusDI · line 28
  • RMAmath.abs(plusDI - minusDI) / (plusDI + minusDI), ADX Length (14)dx · line 29
  • SMAdx, ADX Length (14)adx · line 30

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.

highhighprice dataleftbars Left Barssetting · 6rightbars Right Barssetting · 6lowlowprice dataclosecloseprice datamacdfastMACD Fastsetting · 12macdslowMACD Slowsetting · 26macdsignalMACD Signalsetting · 7high · low · closehigh · low · closeprice datalenADX Lengthsetting · 14longtp1Long TP 1setting · 6longsl1Long SLsetting · 3.0longtp2Long TP 2setting · 12shorttp1Short TP 1 setting · 6.0shortsl1Short SLsetting · 3.0shorttp2Short TP 2setting · 12.0directionDirectionsetting · BothresPivothigh→ ressupPivotlow→ supmacdEMA→ macdsignalEMA→ signalupChange→ updownChange→ downtruerangeRMA→ truerangeplusDIRMA→ plusDIminusDIRMA→ minusDIdxRMA→ dxadxSMA→ adxplusDM, minusDMplusDM · minusDM2 valueslongtakeprofit1longtakeprofit1valuelongstoploss1longstoploss1valuelongtakeprofit2longtakeprofit2valueshorttakeprofit1shorttakeprofit1valueshortstoploss1shortstoploss1valueshorttakeprofit2shorttakeprofit2valuelongconditionlongconditionconditionshortconditionshortconditionconditionentry:longOpen longstrategy.entryexit:exit long 1exit exit long 1strategy.exitexit:exit long 2exit exit long 2strategy.exitcancel:exit long 2cancel exit long 2strategy.cancelexit:exit long 3exit exit long 3strategy.exitentry:shortOpen shortstrategy.entryexit:exit short 1exit exit short 1strategy.exitexit:exit short 2exit exit short 2strategy.exitcancel:exit short 2cancel exit short 2strategy.cancelexit:exit short 3exit exit short 3strategy.exitplot:114plotplotplot:115plotplotplot:116plotplotplot:117plotplotfill:118Fillfill × 4fill:119Fillfill × 4plot:121plotplotplot:122plotplotplot:123plotplotfill:124Fillfill × 4fill:125Fillfill × 4plot:127resplotplot:128supplot

Order rules

OrderFires whenBy defaultLine
Open long longlongcondition and strategy.opentrades == 0On52
Exit exit long 1 stop and limitdirection == "Both"On53
Exit exit long 2 stop and limitdirection == "Both"On54
cancel exit long 2high >= longtakeprofit1On56
Exit exit long 3 stop and limithigh >= longtakeprofit1On57
Open short shortshortcondition and strategy.opentrades == 0On59
Exit exit short 1 stop and limitdirection == "Both"On60
Exit exit short 2 stop and limitdirection == "Both"On61
cancel exit short 2low <= shorttakeprofit1On63
Exit exit short 3 stop and limitdirection == "Both"On64
Open long longlongcondition and strategy.opentrades == 0On67
Exit exit long 1 stop and limitdirection == "Long"On68
Exit exit long 2 stop and limitdirection == "Long"On69
cancel exit long 2high >= longtakeprofit1On71
Exit exit long 3 stop and limithigh >= longtakeprofit1On72
Open short shortshortcondition and strategy.opentrades == 0On75
Exit exit short 1 stop and limitdirection == "Short"On76
Exit exit short 2 stop and limitdirection == "Short"On77
cancel exit short 2low <= shorttakeprofit1On79
Exit exit short 3 stop and limitdirection == "Short"On80
Open long longshortcondition and strategy.opentrades == 0On84
Exit exit long 1 stop and limitdirection == "Both"On85
Exit exit long 2 stop and limitdirection == "Both"On86
cancel exit long 2high >= longtakeprofit1On88
Exit exit long 3 stop and limithigh >= longtakeprofit1On89
Open short shortlongcondition and strategy.opentrades == 0On91
Exit exit short 1 stop and limitdirection == "Both"On92
Exit exit short 2 stop and limitdirection == "Both"On93
cancel exit short 2low <= shorttakeprofit1On95
Exit exit short 3 stop and limitdirection == "Both"On96
Open long longshortcondition and strategy.opentrades == 0On99
Exit exit long 1 stop and limitdirection == "Long"On100
Exit exit long 2 stop and limitdirection == "Long"On101
cancel exit long 2high >= longtakeprofit1On103
Exit exit long 3 stop and limithigh >= longtakeprofit1On104
Open short shortlongcondition and strategy.opentrades == 0On107
Exit exit short 1 stop and limitdirection == "Short"On108
Exit exit short 2 stop and limitdirection == "Short"On109
cancel exit short 2low <= shorttakeprofit1On111
Exit exit short 3 stop and limitdirection == "Short"On112

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.

2/2trades 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+0.3%+102.5%838%1.790.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.0%+5.5%825%0.920.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.0%+9.8%1030%0.970.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%633%1.370.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.0%+16.7%683%204.680.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.8%+21.5%147%0.150.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.3%+148.3%1631%1.330.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%825%0.900.5%8 May 2026 – 21 Oct 2026

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

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair ( Left Bars 6, Right Bars 3) made +0.9% before 26 Dec 2025 and −0.3% after it, worse than the defaults' −0.2% after. Tuning on the past did not carry forward. 98% of the 49 combinations made money in-sample and 0% out-of-sample.

Before 26 Dec 2025 · in-sample
Right Bars ↓ · Left Bars →34567810
3+0%+0%+1%+1%+1%+1%+1%
4+0%+0%+1%+1%+1%+1%+1%
5+0%+0%+1%+1%+1%+1%+1%
6−0%+0%+0%+0%+0%+0%+0%
7+0%+0%+0%+0%+0%+0%+0%
8+0%+0%+0%+0%+0%+0%+0%
10+0%+0%+0%+0%+0%+0%+0%
From 26 Dec 2025 · out-of-sample
Right Bars ↓ · Left Bars →34567810
3−0%−0%−0%−0%−0%−0%−0%
4−0%−0%−0%−0%−0%−0%−0%
5−0%−0%−0%−0%−0%−0%−0%
6−0%−0%−0%−0%−0%−0%−0%
7−0%−0%−0%−0%−0%−0%−0%
8−0%−0%−0%−0%−0%−0%−0%
10−0%−0%−0%−0%−0%−0%−0%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market450%$2.79
Sideways market425%−$0.20
Falling market0—$0.00

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

How bad could the drawdown be?

0.3%

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

0%1%
All 8 trades
SideEntryExitBarsP&L
long7 Nov 2024 75,572.0010 Nov 2024 80,106.303$1.45
long7 Nov 2024 75,572.0011 Nov 2024 84,640.604$2.94
long17 Dec 2024 106,059.0018 Dec 2024 102,877.001−$0.80
long17 Dec 2024 106,059.0018 Dec 2024 102,877.001−$0.80
long9 May 2025 103,262.0021 May 2025 109,457.0012$1.45
long9 May 2025 103,262.0031 May 2025 103,262.0022−$0.05
long5 May 2026 79,861.0017 May 2026 77,465.2012−$0.80
long5 May 2026 79,861.0017 May 2026 77,465.2012−$0.80

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
Ta Strategy this page—v5 strategy+0.3%80.3%
TICK strategy for SPY options by PtGamblerrma ema pivotlow pivothigh smav5 strategyNo trades on this market
Villa Dinamic Pivot Supertrend Strategy by VILIO_Tradingpivothigh pivotlow ema smav5 strategyNo trades on this market
Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10ksma ema rmav4 strategy−19.4%3670.0%
Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGamblerema sma rmav5 strategyNo trades on this market
EMA-ADX-VOL-CRYPTO KILLER [15M] by Babehdyorma sma emav4 strategy+4.5%225.3%

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.

  • 7 settings use the untyped input() (line 8, 9, 10, 11, 12, 13, 14). 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 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
⋯direction = input.string(defval = "Both" , options = ["Both" , "Short" , "Long"] )-leftbars= input(6,title = " Left Bars" , group = "Support and resistance")+leftbars= input.int(6,title = " Left Bars" , group = "Support and resistance")-rightbars = input(6, title = " Right Bars", group = "Support and resistance")+rightbars = input.int(6, title = " Right Bars", group = "Support and resistance")-macdfast = input(12, title = "MACD Fast", group = "MACD")+macdfast = input.int(12, title = "MACD Fast", group = "MACD")-macdslow = input(26, title = "MACD Slow",group = "MACD")+macdslow = input.int(26, title = "MACD Slow",group = "MACD")-macdsignal = input(7, "MACD Signal",group = "MACD")+macdsignal = input.int(7, "MACD Signal",group = "MACD")-sellqty = input(50, title = "QTY to sell at TP 1")+sellqty = input.int(50, title = "QTY to sell at TP 1")-len = input(14, title="ADX Length" , group = "ADX")+len = input.int(14, title="ADX Length" , group = "ADX")// sup and res⋯

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: 8 before, 0 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.

⋯// © AHMEDABDELAZIZZIZO-//@version=5+//@version=6strategy("Ta Strategy", overlay=true,initial_capital = 1000 ,default_qty_type = strategy.percent_of_equity ,default_qty_value = 5 , commission_type = strategy.commission.percent , commission_value = 0.1 )⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 72 msYes 1,000 bars in 118 msNot measured
PineTSNot testedNot testedNot 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.

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/// © AHMEDABDELAZIZZIZO//@version=5strategy("Ta Strategy", overlay=true,initial_capital = 1000 ,default_qty_type = strategy.percent_of_equity ,default_qty_value = 5 , commission_type = strategy.commission.percent , commission_value = 0.1 )// inputsinversestrategy = input.bool(false, title = "Inverse Strategy",tooltip = "This option makes you reverse the strategy so that long signals become where to short  ")direction = input.string(defval = "Both" , options = ["Both" , "Short" , "Long"] )leftbars= input(6,title = " Left Bars" , group = "Support and resistance")rightbars = input(6, title = " Right Bars", group = "Support and resistance")macdfast = input(12, title = "MACD Fast", group = "MACD")macdslow = input(26, title = "MACD Slow",group = "MACD")macdsignal = input(7, "MACD Signal",group = "MACD")sellqty = input(50, title = "QTY to sell at TP 1")len = input(14, title="ADX Length" , group = "ADX")// sup and resres = fixnan(ta.pivothigh(high,leftbars,rightbars))sup = fixnan(ta.pivotlow(low , leftbars,rightbars))// macdmacd =ta.ema(close,macdfast) - ta.ema(close,macdslow)signal=ta.ema(macd,macdsignal)//adxup = ta.change(high)down = -ta.change(low)plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)truerange = ta.rma(ta.tr,len)plusDI = 100 * ta.rma(plusDM, len) / truerangeminusDI = 100 * ta.rma(minusDM, len) / truerangedx = 100 * ta.rma(math.abs(plusDI - minusDI) / (plusDI + minusDI), len)adx = ta.sma(dx, len)// start deal conditionlongcondition =  ta.crossover(macd,signal) and close > res and ta.rsi(close,14) > 50 and plusDI > minusDI and adx > 20 shortcondition = ta.crossunder(macd,signal) and close < sup and ta.rsi(close,14) < 50 and plusDI < minusDI and adx > 20 //tplongtp1   = input.float(6, "Long TP 1", minval = 0.0, step = 0.25, group = "Exit LONG Orders") /100longtp2   = input.float(12, "Long TP 2", minval = 0.0, step = 0.25, group = "Exit LONG Orders") /100longsl1 = input.float(3.0, "Long SL",  minval = 0.0, step = 0.25, group = "Exit LONG Orders") /100longtakeprofit1 = (strategy.position_avg_price * (1 + longtp1)) longstoploss1 = (strategy.position_avg_price * (1 - longsl1)) longtakeprofit2 = (strategy.position_avg_price * (1 + longtp2)) //slshorttp1   = input.float(6.0, "Short TP 1 ", minval = 0.0, step = 0.25, group = "Exit SHORT Orders")/100shorttp2   = input.float(12.0, "Short TP 2", minval = 0.0, step = 0.25, group = "Exit SHORT Orders")/100shortsl1 = input.float(3.0, "Short SL",  minval = 0.0, step = 0.25, group = "Exit SHORT Orders")/100shorttakeprofit1 = (strategy.position_avg_price * (1- shorttp1))shortstoploss1 = (strategy.position_avg_price * (1 + shortsl1))shorttakeprofit2 = (strategy.position_avg_price * (1- shorttp2))//placeordersif inversestrategy == false    if direction == "Both"        if longcondition and strategy.opentrades == 0            strategy.entry("long" , strategy.long )        strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)        strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)        if high >= longtakeprofit1            strategy.cancel("exit long 2")            strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)        if shortcondition and strategy.opentrades == 0            strategy.entry("short",strategy.short)        strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)        strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)        if low <= shorttakeprofit1            strategy.cancel("exit short 2")        strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)    else if direction == "Long"        if longcondition and strategy.opentrades == 0            strategy.entry("long" , strategy.long )        strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)        strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)        if high >= longtakeprofit1            strategy.cancel("exit long 2")            strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)    else if direction == "Short"        if shortcondition and strategy.opentrades == 0            strategy.entry("short",strategy.short)        strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)        strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)        if low <= shorttakeprofit1            strategy.cancel("exit short 2")        strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)else    if direction == "Both"        if shortcondition and strategy.opentrades == 0            strategy.entry("long" , strategy.long )        strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)        strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)        if high >= longtakeprofit1            strategy.cancel("exit long 2")            strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)        if longcondition and strategy.opentrades == 0            strategy.entry("short",strategy.short)        strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)        strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)        if low <= shorttakeprofit1            strategy.cancel("exit short 2")        strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)    else if direction == "Long"        if shortcondition and strategy.opentrades == 0            strategy.entry("long" , strategy.long )        strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)        strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)        if high >= longtakeprofit1            strategy.cancel("exit long 2")            strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)    else if direction == "Short"        if longcondition and strategy.opentrades == 0            strategy.entry("short",strategy.short)        strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)        strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)        if low <= shorttakeprofit1            strategy.cancel("exit short 2")        strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////lsl1 = plot(strategy.position_size <= 0 ? na : longstoploss1, color=color.rgb(124, 11, 11), style=plot.style_linebr, linewidth=1)ltp1 = plot(strategy.position_size <= 0 ? na : longtakeprofit1, color=color.rgb(15, 116, 18), style=plot.style_linebr, linewidth=1)ltp2 = plot(strategy.position_size <= 0 ? na : longtakeprofit2, color=color.rgb(15, 116, 18), style=plot.style_linebr, linewidth=1)avg = plot(strategy.position_avg_price, color=color.rgb(255, 153, 0, 47), style=plot.style_linebr, linewidth=1)fill(ltp1,avg , color =strategy.position_size <= 0 ? na : color.rgb(82, 255, 97, 90))fill(ltp2,ltp1 , color =strategy.position_size <= 0 ? na : color.rgb(82, 255, 97, 90))///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ssl1 = plot(strategy.position_size >= 0 ? na : shortstoploss1, color=color.red, style=plot.style_linebr, linewidth=1)stp1 = plot(strategy.position_size >= 0 ? na : shorttakeprofit2, color=color.green, style=plot.style_linebr, linewidth=1)stp2 = plot(strategy.position_size >= 0 ? na : shorttakeprofit1, color=color.green, style=plot.style_linebr, linewidth=1)fill(stp1,avg , color =strategy.position_size >= 0 ? na : color.rgb(30, 92, 35, 90))fill(stp2,stp1 , color =strategy.position_size >= 0 ? na : color.rgb(30, 92, 35, 90))//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////resplot = plot(res, color=ta.change(res) ? na : #bf141446,  linewidth=3, offset=-(rightbars+1), title="res")supplot = plot(sup, color=ta.change(sup) ? na : #118f113a,  linewidth=3, offset=-(rightbars+1), title="sup")