Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Big Bar 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. 18 settings; defaults include Strategy Direction 0, Bar Body Size .5 and Period for bar size average 10.

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 Big Bar Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
How did Big Bar Strategy do on BTCUSDT 1D with default settings?
−56.59%
From 26 Jan 2024 to 21 Oct 2026, over 13 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Big Bar 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 Big Bar Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 118, 119.
Does Big Bar Strategy run in Zeal Terminal?
Yes
It compiles in 37 ms and runs 1,000 bars in 101 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 (18)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$4,417$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
−56.59%
−$5,659.21
Buy and hold
+102.5%
same period
Closed trades
13
4 won · 9 lost
Profitable
30.8%
of closed trades
Profit factor
0.36
gross profit ÷ gross loss
Max drawdown
57.13%
−$5,713.09

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A short 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 81, 82, 84, 85, 88, 89, 91, 92, 118, 119. 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, sum → math.sum.
  • 10 strategy calls use the when = argument (line 81, 82, 84, 85, 88, 89, 91, 92, 118, 119). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 11: //@version=4 → //@version=5
  • Line 20: input(type = input.integer) → input.int()
  • Line 43: lowest → ta.lowest
  • Line 44: highest → ta.highest
  • Line 45: valuewhen → ta.valuewhen
  • Line 46: valuewhen → ta.valuewhen
10 more edits
  • Line 52: atr → ta.atr
  • Line 55: valuewhen → ta.valuewhen
  • Line 56: valuewhen → ta.valuewhen
  • Line 64: sum → math.sum
  • Line 69: valuewhen → ta.valuewhen
  • Line 70: valuewhen → ta.valuewhen
  • Line 71: valuewhen → ta.valuewhen
  • Line 72: valuewhen → ta.valuewhen
  • Line 98: valuewhen → ta.valuewhen
  • Line 110: valuewhen → ta.valuewhen
⋯// which can also be modified, as well as the required size of the Big Bar relative to this period average.-//@version=4+//@version=5strategy("Big Bar Strategy", ⋯     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))⋯// 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 ⋯barbodysize=close>open?(open-close)*-1:(open-close)-barsizeavg=sum(barsize, period)/period+barsizeavg=math.sum(barsize, period)/periodbigbar=barsize >= barsizeavg*mult and barbodysize>barsize*barsizeThreshold⋯barsizemult=input(1, step=.1, title="Strategy SL/TP Mult")-float LongStop = strategy.position_avg_price - (valuewhen(bought,barsize,0)*barsizemult)+float LongStop = strategy.position_avg_price - (ta.valuewhen(bought,barsize,0)*barsizemult)-float ShortStop = strategy.position_avg_price + (valuewhen(bought,barsize,0)*barsizemult)+float ShortStop = strategy.position_avg_price + (ta.valuewhen(bought,barsize,0)*barsizemult)-float StratTP = strategy.position_avg_price + (valuewhen(bought,barsize,0)*barsizemult)+float StratTP = strategy.position_avg_price + (ta.valuewhen(bought,barsize,0)*barsizemult)-float StratSTP = strategy.position_avg_price - (valuewhen(bought,barsize,0)*barsizemult)+float StratSTP = strategy.position_avg_price - (ta.valuewhen(bought,barsize,0)*barsizemult)BUY=i_Confirmation ? close[1] < open[1] and bigbar[1] and close > open : close < open and bigbar⋯//TrailingStop-dif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0))+dif=(ta.valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0)) -strategy.position_avg_price⋯var Ststop = float(na)-Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0 +Sdif=strategy.position_avg_price-(ta.valuewhen(strategy.position_size<0  and strategy.position_size[1]>=0, low,0))⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 23: input() → input.bool()
  • Line 24: input() → input.float()
  • Line 25: input() → input.int()
  • Line 26: input() → input.int()
  • Line 27: input() → input.bool()
  • Line 29: input() → input.bool()
21 more edits
  • Line 31: input() → input.bool()
  • Line 32: input() → input.string()
  • Line 33: input() → input.int()
  • Line 34: input() → input.int()
  • Line 35: input() → input.int()
  • Line 36: input() → input.int()
  • Line 37: input() → input.int()
  • Line 38: input() → input.bool()
  • Line 68: input() → input.int()
  • Line 76: input() → input.bool()
  • Line 77: input() → input.bool()
  • Line 81: when = SELL and strategy.position_size == 0 → if block
  • Line 82: when = BUY and strategy.position_size == 0 → if block
  • Line 84: when = SELL → if block
  • Line 85: when = BUY → if block
  • Line 88: when = BUY and strategy.position_size == 0 → if block
  • Line 89: when = SELL and strategy.position_size == 0 → if block
  • Line 91: when = BUY → if block
  • Line 92: when = SELL → if block
  • Line 118: when = i_SL → if block
  • Line 119: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------")  +title1=input.bool(true, "-----------------Strategy Inputs-------------------")  -barsizeThreshold=input(.5, step=.1, minval=.5, maxval=.9, title="Bar Body Size")+barsizeThreshold=input.float(.5, step=.1, minval=.5, maxval=.9, title="Bar Body Size")-period=input(10, title="Period for bar size average")+period=input.int(10, title="Period for bar size average")-mult=input(2, step=.2, title="Big Size Avg Mult to determine Big Bar")+mult=input.int(2, step=.2, title="Big Size Avg Mult to determine Big Bar")-i_Confirmation=input(true, title="Enter trade after confirmation bar")+i_Confirmation=input.bool(true, title="Enter trade after confirmation bar")/////////////////////// 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=3, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.int(defval=3, 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(4, step=.1, title="ATR Multiple")+i_ATRMult = input.int(4, step=.1, title="ATR Multiple")-i_TPRRR = input(1, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.int(1, step=.1, title="Take Profit Risk Reward Ratio")-TS=input(false, title="Trailing Stop")+TS=input.bool(false, title="Trailing Stop")// Bought and Sold Boolean Signal⋯// Strategy Stop-barsizemult=input(1, step=.1, title="Strategy SL/TP Mult")+barsizemult=input.int(1, step=.1, title="Strategy SL/TP Mult")float LongStop = strategy.position_avg_price - (ta.valuewhen(bought,barsize,0)*barsizemult)⋯//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⋯    Ststop := na-strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL, when=i_SL)+if i_SL+    strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL)-strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL, when=i_SL)+if i_SL+    strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : 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: 13 before, 17 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.

⋯// which can also be modified, as well as the required size of the Big Bar relative to this period average.-//@version=5+//@version=6strategy("Big Bar Strategy", ⋯

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 21
-----------------Strategy Inputs-------------------trueboolunused
Bar Body Size.5float · min .5 · max .9 · step .1bigbar
Period for bar size average10intbarsizeavg
Big Size Avg Mult to determine Big Bar2int · step .2bigbar
Enter trade after confirmation bartrueboolBUY 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 Increment3int · step .1LL HH
ATR Length14intATR
ATR Multiple4int · step .1ATR
Take Profit Risk Reward Ratio1int · step .1tp stp ATRtp ATRstp
Trailing Stopfalseboolexit TP & SL SL SSL
Strategy SL/TP Mult1int · step .1LongStop ShortStop StratTP StratSTP
Allow Direct Position Reversetrueboolentry long entry short entry long entry short entry long entry short entry long entry short line 80 line 87
Reverse Tradesfalseboolline 79

What it calculates

  • Lowest (lowest, ta.lowest in v5)Swing Point Lookback (10)LL · line 43
  • Highest (highest, ta.highest in v5)Swing Point Lookback (10)HH · line 44
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, LL, 0LL_price · line 45
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, HH, 0HH_price · line 46
  • ATR (atr, ta.atr in v5)ATR Length (14)ATR · line 52
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, ATRLong, 0ATRLongStop · line 55
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, ATRShort, 0ATRShortStop · line 56
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, barsize, 0LongStop · line 69
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, barsize, 0ShortStop · line 70
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, barsize, 0StratTP · line 71
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, barsize, 0StratSTP · line 72

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

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

Order rules

OrderFires whenBy defaultLine
Open long longSELL and strategy.position_size == 0On81
Open short shortBUY and strategy.position_size == 0On82
Open long longSELLOn84
Open short shortBUYOn85
Open long longBUY and strategy.position_size == 0On88
Open short shortSELL and strategy.position_size == 0On89
Open long longBUYOn91
Open short shortSELLOn92
Exit TP & SL stop and limiti_SLOn118
Exit TP & SL stop and limiti_SLOn119

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.

3/3trades 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−56.6%+102.5%1331%0.3657.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−22.3%+5.5%2148%0.4430.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−76.8%+9.8%1127%0.1384.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−23.1%+8.4%1741%0.4530.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+142.3%+16.7%560%31.1936.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.0%+21.5%1663%1.0223.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+20.4%+148.3%1070%1.3440.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.8%+17.1%1457%1.0915.7%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 market450%−$1,674.66
Sideways market633%−$1,437.16
Falling market30%−$2,545.66

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

How bad could the drawdown be?

68.4%

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

0%79%
All 13 trades
SideEntryExitBarsP&L
short1 Mar 2024 61,131.0011 Mar 2024 70,598.4010−$1,556.70
short17 May 2024 65,235.2026 Jun 2024 61,806.0040$437.08
long26 Jun 2024 61,806.005 Aug 2024 53,369.5040−$1,218.75
short13 Nov 2024 87,952.005 Dec 2024 103,303.0022−$1,343.37
long28 Feb 2025 84,708.608 May 2025 102,118.0069$1,292.43
short10 May 2025 102,972.007 Jun 2025 104,288.0028−$103.39
long7 Jun 2025 104,288.0010 Jul 2025 115,327.0033$788.32
long27 Sep 2025 109,643.002 Oct 2025 118,879.005$691.60
long6 Nov 2025 103,885.0020 Nov 2025 86,118.3014−$1,542.99
long3 Dec 2025 91,277.9031 Jan 2026 76,846.2059−$1,182.00
long7 Feb 2026 70,580.3027 Feb 2026 67,485.2020−$279.40
short27 Feb 2026 67,485.204 May 2026 79,656.5066−$1,084.26
short23 Aug 2026 77,074.9021 Sep 2026 85,762.4029−$556.06

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
Big Bar Strategy this page—v4 strategy−56.6%1357.1%
Positive Bars - Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−40.3%754.7%
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 37 msWith a workaround 1,000 bars in 101 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/// © tweakerID// This strategy detects and uses big bars to enter a position. When the Big Bar // is bearish (red candle) the position will be long and viceversa// for short positions. The stop loss (optional) is placed on the low of the // candle used to trigger the position and user inputs allow you to modify the// size of the SL. Take profit is placed on a reward ratio of 1. User can also modify // the size of the bar body used to determine if we have a real Big Bar and// filter out Doji bars. Big Bars are determined relative to the previous X period size, // which can also be modified, as well as the required size of the Big Bar relative to this period average.//@version=4strategy("Big Bar Strategy",      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-------------------")  barsizeThreshold=input(.5, step=.1, minval=.5, maxval=.9, title="Bar Body Size")period=input(10, title="Period for bar size average")mult=input(2, step=.2, title="Big Size Avg Mult to determine Big Bar")i_Confirmation=input(true, title="Enter trade after confirmation bar")/////////////////////// 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=3, step=.1, title="Swing Point SL Perc Increment")*0.01i_ATR = input(14, title="ATR Length")i_ATRMult = input(4, step=.1, title="ATR Multiple")i_TPRRR = input(1, step=.1, title="Take Profit Risk Reward Ratio")TS=input(false, title="Trailing Stop")// 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 LOGIC /////////////////////////////////////////barsize=high-lowbarbodysize=close>open?(open-close)*-1:(open-close)barsizeavg=sum(barsize, period)/periodbigbar=barsize >= barsizeavg*mult and barbodysize>barsize*barsizeThresholdbarcolor(bigbar ? color.white : na)// Strategy Stopbarsizemult=input(1, step=.1, title="Strategy SL/TP Mult")float LongStop = strategy.position_avg_price - (valuewhen(bought,barsize,0)*barsizemult)float ShortStop = strategy.position_avg_price + (valuewhen(bought,barsize,0)*barsizemult)float StratTP = strategy.position_avg_price + (valuewhen(bought,barsize,0)*barsizemult)float StratSTP = strategy.position_avg_price - (valuewhen(bought,barsize,0)*barsizemult)BUY=i_Confirmation ? close[1] < open[1] and bigbar[1] and close > open : close < open and bigbarSELL=i_Confirmation ? close[1] > open[1] and bigbar[1] and close < open : close > open and bigbar//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 : StratSTP//TrailingStopdif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0)) -strategy.position_avg_pricetrailOffset     = strategy.position_avg_price - SLvar tstop = float(na)if strategy.position_size > 0    tstop := high- trailOffset - dif    if tstop<tstop[1]        tstop:=tstop[1]else    tstop := naStrailOffset     = SSL - strategy.position_avg_pricevar Ststop = float(na)Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0  and strategy.position_size[1]>=0, low,0))if strategy.position_size < 0    Ststop := low+ StrailOffset + Sdif    if Ststop>Ststop[1]        Ststop:=Ststop[1]else    Ststop := nastrategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL, when=i_SL)strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL, when=i_SL)/////////////////////// PLOTS //////////////////////////////////////////////////plot(i_SL and strategy.position_size > 0 and not TS ? SL : i_SL and strategy.position_size > 0 and TS ? tstop : na , title='SL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size < 0 and not TS ? SSL : i_SL and strategy.position_size < 0 and TS ? Ststop : 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)