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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Inverse StrategyThis option makes you reverse the strategy so that long signals become where to short | false | bool | line 49 |
| Direction (no label in the script) | Both | string · 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 1 | 50 | int | exit exit long 1 exit exit short 1 |
| Support and resistance | |||
| Left Bars | 6 | int | res sup |
| Right Bars | 6 | int | res sup res sup |
| MACD | |||
| MACD Fast | 12 | int | macd |
| MACD Slow | 26 | int | macd |
| MACD Signal | 7 | int | signal |
| ADX | |||
| ADX Length | 14 | int | truerange plusDI minusDI dx adx |
| Exit LONG Orders | |||
| Long TP 1 | 6 | float · min 0.0 · step 0.25 | longtakeprofit1 |
| Long TP 2 | 12 | float · min 0.0 · step 0.25 | longtakeprofit2 |
| Long SL | 3.0 | float · min 0.0 · step 0.25 | longstoploss1 |
| Exit SHORT Orders | |||
| Short TP 1 | 6.0 | float · min 0.0 · step 0.25 | shorttakeprofit1 |
| Short TP 2 | 12.0 | float · min 0.0 · step 0.25 | shorttakeprofit2 |
| Short SL | 3.0 | float · min 0.0 · step 0.25 | shortstoploss1 |
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 - Changehigh
up · line 22 - Changelow
down · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longcondition and strategy.opentrades == 0 | On | 52 |
| Exit exit long 1 stop and limit | direction == "Both" | On | 53 |
| Exit exit long 2 stop and limit | direction == "Both" | On | 54 |
| cancel exit long 2 | high >= longtakeprofit1 | On | 56 |
| Exit exit long 3 stop and limit | high >= longtakeprofit1 | On | 57 |
| Open short short | shortcondition and strategy.opentrades == 0 | On | 59 |
| Exit exit short 1 stop and limit | direction == "Both" | On | 60 |
| Exit exit short 2 stop and limit | direction == "Both" | On | 61 |
| cancel exit short 2 | low <= shorttakeprofit1 | On | 63 |
| Exit exit short 3 stop and limit | direction == "Both" | On | 64 |
| Open long long | longcondition and strategy.opentrades == 0 | On | 67 |
| Exit exit long 1 stop and limit | direction == "Long" | On | 68 |
| Exit exit long 2 stop and limit | direction == "Long" | On | 69 |
| cancel exit long 2 | high >= longtakeprofit1 | On | 71 |
| Exit exit long 3 stop and limit | high >= longtakeprofit1 | On | 72 |
| Open short short | shortcondition and strategy.opentrades == 0 | On | 75 |
| Exit exit short 1 stop and limit | direction == "Short" | On | 76 |
| Exit exit short 2 stop and limit | direction == "Short" | On | 77 |
| cancel exit short 2 | low <= shorttakeprofit1 | On | 79 |
| Exit exit short 3 stop and limit | direction == "Short" | On | 80 |
| Open long long | shortcondition and strategy.opentrades == 0 | On | 84 |
| Exit exit long 1 stop and limit | direction == "Both" | On | 85 |
| Exit exit long 2 stop and limit | direction == "Both" | On | 86 |
| cancel exit long 2 | high >= longtakeprofit1 | On | 88 |
| Exit exit long 3 stop and limit | high >= longtakeprofit1 | On | 89 |
| Open short short | longcondition and strategy.opentrades == 0 | On | 91 |
| Exit exit short 1 stop and limit | direction == "Both" | On | 92 |
| Exit exit short 2 stop and limit | direction == "Both" | On | 93 |
| cancel exit short 2 | low <= shorttakeprofit1 | On | 95 |
| Exit exit short 3 stop and limit | direction == "Both" | On | 96 |
| Open long long | shortcondition and strategy.opentrades == 0 | On | 99 |
| Exit exit long 1 stop and limit | direction == "Long" | On | 100 |
| Exit exit long 2 stop and limit | direction == "Long" | On | 101 |
| cancel exit long 2 | high >= longtakeprofit1 | On | 103 |
| Exit exit long 3 stop and limit | high >= longtakeprofit1 | On | 104 |
| Open short short | longcondition and strategy.opentrades == 0 | On | 107 |
| Exit exit short 1 stop and limit | direction == "Short" | On | 108 |
| Exit exit short 2 stop and limit | direction == "Short" | On | 109 |
| cancel exit short 2 | low <= shorttakeprofit1 | On | 111 |
| Exit exit short 3 stop and limit | direction == "Short" | On | 112 |
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.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +0.3% | +102.5% | 8 | 38% | 1.79 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.0% | +5.5% | 8 | 25% | 0.92 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.0% | +9.8% | 10 | 30% | 0.97 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.1% | +8.4% | 6 | 33% | 1.37 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1.0% | +16.7% | 6 | 83% | 204.68 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.8% | +21.5% | 14 | 7% | 0.15 | 0.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.3% | +148.3% | 16 | 31% | 1.33 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 8 | 25% | 0.90 | 0.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.
| Right Bars ↓ · Left Bars → | 3 | 4 | 5 | 6 | 7 | 8 | 10 |
|---|---|---|---|---|---|---|---|
| 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% |
| Right Bars ↓ · Left Bars → | 3 | 4 | 5 | 6 | 7 | 8 | 10 |
|---|---|---|---|---|---|---|---|
| 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 4 | 50% | $2.79 |
| Sideways market | 4 | 25% | −$0.20 |
| Falling market | 0 | — | $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.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 7 Nov 2024 75,572.00 | 10 Nov 2024 80,106.30 | 3 | $1.45 |
| long | 7 Nov 2024 75,572.00 | 11 Nov 2024 84,640.60 | 4 | $2.94 |
| long | 17 Dec 2024 106,059.00 | 18 Dec 2024 102,877.00 | 1 | −$0.80 |
| long | 17 Dec 2024 106,059.00 | 18 Dec 2024 102,877.00 | 1 | −$0.80 |
| long | 9 May 2025 103,262.00 | 21 May 2025 109,457.00 | 12 | $1.45 |
| long | 9 May 2025 103,262.00 | 31 May 2025 103,262.00 | 22 | −$0.05 |
| long | 5 May 2026 79,861.00 | 17 May 2026 77,465.20 | 12 | −$0.80 |
| long | 5 May 2026 79,861.00 | 17 May 2026 77,465.20 | 12 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Ta Strategy this page | — | v5 strategy | +0.3% | 8 | 0.3% |
| TICK strategy for SPY options by PtGambler | rma ema pivotlow pivothigh sma | v5 strategy | No trades on this market | ||
| Villa Dinamic Pivot Supertrend Strategy by VILIO_Trading | pivothigh pivotlow ema sma | v5 strategy | No trades on this market | ||
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGambler | ema sma rma | v5 strategy | No trades on this market | ||
| EMA-ADX-VOL-CRYPTO KILLER [15M] by Babehdyo | rma sma ema | v4 strategy | +4.5% | 22 | 5.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.
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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 72 ms | Yes 1,000 bars in 118 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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")