Pine Script v4 · Strategy
Positive Bars - 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. 15 settings; defaults include Strategy Direction 0, Lookback 13 and Upper Limit 70.
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 Positive Bars - 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 Positive Bars - Strategy do on BTCUSDT 1D with default settings?
- −40.30%
- From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Positive Bars - 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 Positive Bars - Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 93, 94.
- Does Positive Bars - Strategy run in Zeal Terminal?
- Yes
- It compiles in 29 ms and runs 1,000 bars in 81 ms, in the browser.
BTCUSDT · 1D · default settings
- SL
- SSL
- TP
- STP
- Bullish Setup
- Bearish Setup
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −40.30%
- −$4,030.16
- Buy and hold
- +102.5%
- same period
- Closed trades
- 7
- 2 won · 5 lost
- Profitable
- 28.6%
- of closed trades
- Profit factor
- 0.51
- gross profit ÷ gross loss
- Max drawdown
- 54.68%
- −$6,728.56
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
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 77, 78, 80, 81, 84, 85, 87, 88, 93, 94. The upgraded version below moves each call inside an if block.
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, atr → ta.atr.
- 10 strategy calls use the when = argument (line 77, 78, 80, 81, 84, 85, 87, 88, 93, 94). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 9: //@version=4 → //@version=5
- Line 18: input(type = input.integer) → input.int()
- Line 22: input(type = input.integer) → input.int()
- Line 23: input(type = input.integer) → input.int()
- Line 24: input(type = input.integer) → input.int()
- Line 39: lowest → ta.lowest
6 more edits
- Line 40: highest → ta.highest
- Line 41: valuewhen → ta.valuewhen
- Line 42: valuewhen → ta.valuewhen
- Line 48: atr → ta.atr
- Line 51: valuewhen → ta.valuewhen
- Line 52: valuewhen → ta.valuewhen
⋯// this logic can be reversed with positive results on different time frames.-//@version=4+//@version=5strategy("Positive Bars % Strat", ⋯ 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))⋯title1=input(true, "-----------------Strategy Inputs-------------------") -lookback = input(title="Lookback", type=input.integer, defval=13)+lookback = input.int(title="Lookback", defval=13)-upperLimit = input(title="Upper Limit", type=input.integer, defval=70)+upperLimit = input.int(title="Upper Limit", defval=70)-lowerLimit = input(title="Lower Limit", type=input.integer, defval=30)+lowerLimit = input.int(title="Lower Limit", defval=30)/////////////////////// BACKTESTER /////////////////////////////////////////////⋯// 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 ⋯// ATR Stop-ATR=atr(i_ATR)*i_ATRMult+ATR=ta.atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATR-ATRLongStop = valuewhen(bought, ATRLong, 0)+ATRLongStop = ta.valuewhen(bought, ATRLong, 0)-ATRShortStop = valuewhen(bought, ATRShort, 0)+ATRShortStop = ta.valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ⋯Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 21: input() → input.bool()
- Line 26: input() → input.bool()
- Line 28: input() → input.bool()
- Line 29: input() → input.string()
- Line 30: input() → input.int()
- Line 31: input() → input.int()
15 more edits
- Line 32: input() → input.int()
- Line 33: input() → input.int()
- Line 34: input() → input.float()
- Line 72: input() → input.bool()
- Line 73: input() → input.bool()
- Line 77: when = SELL and strategy.position_size == 0 → if block
- Line 78: when = BUY and strategy.position_size == 0 → if block
- Line 80: when = SELL → if block
- Line 81: when = BUY → if block
- Line 84: when = BUY and strategy.position_size == 0 → if block
- Line 85: when = SELL and strategy.position_size == 0 → if block
- Line 87: when = BUY → if block
- Line 88: when = SELL → if block
- Line 93: when = i_SL → if block
- Line 94: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------") +title1=input.bool(true, "-----------------Strategy Inputs-------------------") lookback = input.int(title="Lookback", defval=13)⋯/////////////////////// BACKTESTER /////////////////////////////////////////////-title2=input(true, "-----------------General Inputs-------------------") +title2=input.bool(true, "-----------------General Inputs-------------------") // Backtester General Inputs-i_SL=input(true, title="Use Stop Loss and Take Profit")+i_SL=input.bool(true, title="Use Stop Loss and Take Profit")-i_SLType=input(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])+i_SLType=input.string(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])-i_SPL=input(defval=10, title="Swing Point Lookback")+i_SPL=input.int(defval=10, title="Swing Point Lookback")-i_PercIncrement=input(defval=2, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.int(defval=2, step=.1, title="Swing Point SL Perc Increment")*0.01-i_ATR = input(14, title="ATR Length")+i_ATR = input.int(14, title="ATR Length")-i_ATRMult = input(10, step=.1, title="ATR Multiple")+i_ATRMult = input.int(10, step=.1, title="ATR Multiple")-i_TPRRR = input(1.6, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.float(1.6, step=.1, title="Take Profit Risk Reward Ratio")// Bought and Sold Boolean Signal⋯//Trading Inputs-DPR=input(true, "Allow Direct Position Reverse")+DPR=input.bool(true, "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= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStop⋯STP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTP-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: 7 before, 30 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.
⋯// this logic can be reversed with positive results on different time frames.-//@version=5+//@version=6strategy("Positive Bars % Strat", ⋯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 |
|---|---|---|---|
| Strategy Direction | 0 | int (written input.integer) · min -1 · max 1 | line 19 |
| -----------------Strategy Inputs------------------- | true | bool | unused |
| Lookback | 13 | int (written input.integer) | i positiveBarsPercent |
| Upper Limit | 70 | int (written input.integer) | BUY |
| Lower Limit | 30 | int (written input.integer) | SELL |
| -----------------General Inputs------------------- | true | bool | unused |
| Use Stop Loss and Take Profit | true | bool | exit TP & SL SL SSL TP STP |
| Type Of Stop | ATR Stop | string · options ["Strategy Stop", "Swing Lo/Hi", "ATR Stop"] | SL SSL TP STP |
| Swing Point Lookback | 10 | int | LL HH |
| Swing Point SL Perc Increment | 2 | int · step .1 | LL HH |
| ATR Length | 14 | int | ATR |
| ATR Multiple | 10 | int · step .1 | ATR |
| Take Profit Risk Reward Ratio | 1.6 | float · step .1 | tp stp ATRtp ATRstp |
| Allow Direct Position Reverse | true | bool | entry long entry short entry long entry short entry long entry short entry long entry short line 76 line 83 |
| Reverse Trades | false | bool | line 75 |
What it calculates
- Lowest (
lowest,ta.lowestin v5)Swing Point Lookback (10)LL · line 39 - Highest (
highest,ta.highestin v5)Swing Point Lookback (10)HH · line 40 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, LL, 0LL_price · line 41 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, HH, 0HH_price · line 42 - ATR (
atr,ta.atrin v5)ATR Length (14)ATR · line 48 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRLong, 0ATRLongStop · line 51 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRShort, 0ATRShortStop · line 52
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 | SELL and strategy.position_size == 0 | On | 77 |
| Open short short | BUY and strategy.position_size == 0 | On | 78 |
| Open long long | SELLpositiveBarsPercent <= lowerLimit | On | 80 |
| Open short short | BUYpositiveBarsPercent >= upperLimit | On | 81 |
| Open long long | BUY and strategy.position_size == 0 | On | 84 |
| Open short short | SELL and strategy.position_size == 0 | On | 85 |
| Open long long | BUYpositiveBarsPercent >= upperLimit | On | 87 |
| Open short short | SELLpositiveBarsPercent <= lowerLimit | On | 88 |
| Exit TP & SL stop and limit | i_SL | On | 93 |
| Exit TP & SL stop and limit | i_SL | On | 94 |
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 | −40.3% | +102.5% | 7 | 29% | 0.51 | 54.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +40.9% | +5.5% | 8 | 63% | 8.57 | 7.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −85.4% | +9.8% | 7 | 29% | 0.15 | 90.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.3% | +8.4% | 6 | 50% | 1.04 | 21.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −88.2% | +16.7% | 17 | 29% | 0.25 | 89.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.2% | +21.5% | 5 | 40% | 1.05 | 19.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −60.3% | +148.3% | 12 | 42% | 0.60 | 64.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −21.2% | +17.1% | 10 | 20% | 0.46 | 32.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 100% | $4,248.49 |
| Sideways market | 2 | 0% | −$3,128.22 |
| Falling market | 3 | 0% | −$5,148.04 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
60.9%
The 95th percentile of the worst drawdown when the same 7 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 40.3% to 60.9%; the tick is what actually happened, 51.5%. Order luck alone moves it this much.
All 7 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 27 Jan 2024 41,823.50 | 13 Feb 2024 49,917.30 | 17 | −$1,943.22 |
| long | 13 Feb 2024 49,917.30 | 6 Nov 2024 74,146.40 | 267 | $3,903.38 |
| short | 7 Feb 2025 96,554.40 | 24 Apr 2025 93,691.10 | 76 | $345.11 |
| long | 24 Apr 2025 93,691.10 | 23 Nov 2025 84,739.80 | 213 | −$1,185.00 |
| short | 23 Nov 2025 84,739.80 | 6 Jan 2026 93,859.70 | 44 | −$1,206.17 |
| long | 6 Jan 2026 93,859.70 | 5 Feb 2026 67,904.20 | 30 | −$2,748.69 |
| short | 11 Feb 2026 68,841.30 | 28 Aug 2026 80,249.60 | 198 | −$1,193.17 |
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 |
|---|---|---|---|---|---|
| Positive Bars - Strategy this page | — | v4 strategy | −40.3% | 7 | 54.7% |
| Big Bar Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −56.6% | 13 | 57.1% |
| SuperTrend Multi Time Frame Long and Short Trading Strategy by ranga_technologies | atr highest lowest valuewhen | v5 strategy | No trades on this market | ||
| Inside Bar Strategy w- SL by tweakerID | lowest highest valuewhen atr | v4 strategy | −61.3% | 25 | 65.0% |
| Modulo Logic + EMA Strat by tweakerID | lowest highest valuewhen atr | v4 strategy | −50.8% | 16 | 54.7% |
| Delayed RSI Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −40.4% | 7 | 42.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 29 ms | With a workaround 1,000 bars in 81 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not 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. 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/// © ZenAndTheArtOfTrading // © TweakerID// Based on the calculations by ZenAndTheArtOfTrading, I added stop loss, take profit and reverse line codes.// The Positive Bars % calculates the number of green (positive) bars, relative to a lookback period, defined // by the user. If the percentage is low, it means that there was a bigger number of red candles in the // lookback period. The strategy goes long when the percentage is high and short when it's low, although// this logic can be reversed with positive results on different time frames.//@version=4strategy("Positive Bars % Strat", 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-------------------") lookback = input(title="Lookback", type=input.integer, defval=13)upperLimit = input(title="Upper Limit", type=input.integer, defval=70)lowerLimit = input(title="Lower Limit", type=input.integer, defval=30)/////////////////////// BACKTESTER /////////////////////////////////////////////title2=input(true, "-----------------General Inputs-------------------") // Backtester General Inputsi_SL=input(true, title="Use Stop Loss and Take Profit")i_SLType=input(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])i_SPL=input(defval=10, title="Swing Point Lookback")i_PercIncrement=input(defval=2, step=.1, title="Swing Point SL Perc Increment")*0.01i_ATR = input(14, title="ATR Length")i_ATRMult = input(10, step=.1, title="ATR Multiple")i_TPRRR = input(1.6, 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// ATR StopATR=atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATRATRLongStop = valuewhen(bought, ATRLong, 0)ATRShortStop = valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ShortSL_ATR_price = strategy.position_size < 0 ? ATRShortStop : na ATRtp=strategy.position_avg_price + (strategy.position_avg_price - LongSL_ATR_price)*i_TPRRRATRstp=strategy.position_avg_price - (ShortSL_ATR_price - strategy.position_avg_price)*i_TPRRR// Strategy Stopfloat LongStop = nafloat ShortStop = nafloat StratTP = nafloat StratSTP = na/////////////////////// STRATEGY LOGIC ///////////////////////////////////////////CalculationspositiveBars = 0for i = (lookback - 1) to 0 if close[i] > open[i] positiveBars := positiveBars + 1positiveBarsPercent = (positiveBars / lookback) * 100BUY=positiveBarsPercent >= upperLimitSELL=positiveBarsPercent <= lowerLimit//Trading InputsDPR=input(true, "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= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStopSSL= i_SLType == "Swing Lo/Hi" ? entry_HH_price : i_SLType == "ATR Stop" ? ShortSL_ATR_price : ShortStopTP= i_SLType == "Swing Lo/Hi" ? tp : i_SLType == "ATR Stop" ? ATRtp : StratTPSTP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTPstrategy.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(i_SL and strategy.position_size > 0 ? SL : na , title='SL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size < 0 ? SSL : na , title='SSL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)plot(i_SL and 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", size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish Setup", size=size.auto)