Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (15)
0.0050,000100,000150,000AprJulOct2025AprJulOct2026AprJulOct$6,302$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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.
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

Verified

Same 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 ⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Strategy Direction0int (written input.integer) · min -1 · max 1line 19
-----------------Strategy Inputs-------------------trueboolunused
Lookback13int (written input.integer)i positiveBarsPercent
Upper Limit70int (written input.integer)BUY
Lower Limit30int (written input.integer)SELL
-----------------General Inputs-------------------trueboolunused
Use Stop Loss and Take Profittrueboolexit TP & SL SL SSL TP STP
Type Of StopATR Stopstring · options ["Strategy Stop", "Swing Lo/Hi", "ATR Stop"]SL SSL TP STP
Swing Point Lookback10intLL HH
Swing Point SL Perc Increment2int · step .1LL HH
ATR Length14intATR
ATR Multiple10int · step .1ATR
Take Profit Risk Reward Ratio1.6float · step .1tp stp ATRtp ATRstp
Allow Direct Position Reversetrueboolentry long entry short entry long entry short entry long entry short entry long entry short line 76 line 83
Reverse Tradesfalseboolline 75

What it calculates

  • Lowest (lowest, ta.lowest in v5)Swing Point Lookback (10)LL · line 39
  • Highest (highest, ta.highest in v5)Swing Point Lookback (10)HH · line 40
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, LL, 0LL_price · line 41
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, HH, 0HH_price · line 42
  • ATR (atr, ta.atr in v5)ATR Length (14)ATR · line 48
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, ATRLong, 0ATRLongStop · line 51
  • Valuewhen (valuewhen, ta.valuewhen in 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.

i_SPLSwing Point Lookbacksetting · 10i_PercIncrementSwing Point SL Perc Inc…setting · 2high · low · closehigh · low · closeprice datai_ATRATR Lengthsetting · 14i_ATRMultATR Multiplesetting · 10i_TPRRRTake Profit Risk Reward…setting · 1.6ohlc4ohlc4price datalookbackLookbacksetting · 13i_SLTypeType Of Stopsetting · ATR StopupperLimitUpper Limitsetting · 70lowerLimitLower Limitsetting · 30LLLowest→ LLHHHighest→ HHLL_priceValuewhen→ LL_priceHH_priceValuewhen→ HH_priceATRATR→ ATRATRLongStopValuewhen→ ATRLongStopATRShortStopValuewhen→ ATRShortStopentry_LL_priceentry_LL_pricevalueentry_HH_priceentry_HH_pricevaluetptpvaluestpstpvalueATRLong, ATRShortATRLong · ATRShort2 valuesLongSL_ATR_priceLongSL_ATR_pricevalueShortSL_ATR_priceShortSL_ATR_pricevalueATRtpATRtpvalueATRstpATRstpvaluepositiveBarspositiveBarsvalueiivaluepositiveBarsPercentpositiveBarsPercentvalueSLSLvalueSSLSSLvalueTPTPvalueSTPSTPvalueBUYBUYconditionSELLSELLconditionboughtboughtconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryexit:TP & SLexit TP & SLstrategy.exitplot:96SLplotplot:97SSLplotplot:98TPplotplot:99STPplotplotshape:101Bullish Setupplotshapeplotshape:103Bearish Setupplotshape

Order rules

OrderFires whenBy defaultLine
Open long longSELL and strategy.position_size == 0On77
Open short shortBUY and strategy.position_size == 0On78
Open long longSELLpositiveBarsPercent <= lowerLimitOn80
Open short shortBUYpositiveBarsPercent >= upperLimitOn81
Open long longBUY and strategy.position_size == 0On84
Open short shortSELL and strategy.position_size == 0On85
Open long longBUYpositiveBarsPercent >= upperLimitOn87
Open short shortSELLpositiveBarsPercent <= lowerLimitOn88
Exit TP & SL stop and limiti_SLOn93
Exit TP & SL stop and limiti_SLOn94

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−40.3%+102.5%729%0.5154.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+40.9%+5.5%863%8.577.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−85.4%+9.8%729%0.1590.8%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+1.3%+8.4%650%1.0421.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−88.2%+16.7%1729%0.2589.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.2%+21.5%540%1.0519.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−60.3%+148.3%1242%0.6064.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−21.2%+17.1%1020%0.4632.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 barsTradesWonP&L
Rising market2100%$4,248.49
Sideways market20%−$3,128.22
Falling market30%−$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.

0%70%
All 7 trades
SideEntryExitBarsP&L
short27 Jan 2024 41,823.5013 Feb 2024 49,917.3017−$1,943.22
long13 Feb 2024 49,917.306 Nov 2024 74,146.40267$3,903.38
short7 Feb 2025 96,554.4024 Apr 2025 93,691.1076$345.11
long24 Apr 2025 93,691.1023 Nov 2025 84,739.80213−$1,185.00
short23 Nov 2025 84,739.806 Jan 2026 93,859.7044−$1,206.17
long6 Jan 2026 93,859.705 Feb 2026 67,904.2030−$2,748.69
short11 Feb 2026 68,841.3028 Aug 2026 80,249.60198−$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.

ScriptSharesTypeNetTradesMax drawdown
Positive Bars - Strategy this page—v4 strategy−40.3%754.7%
Big Bar Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−56.6%1357.1%
SuperTrend Multi Time Frame Long and Short Trading Strategy by ranga_technologiesatr highest lowest valuewhenv5 strategyNo trades on this market
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%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 29 msWith a workaround 1,000 bars in 81 msNot measured
PineTSNo 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)