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
- 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
VerifiedSame 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))⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Strategy Direction | 0 | int (written input.integer) · min -1 · max 1 | line 21 |
| -----------------Strategy Inputs------------------- | true | bool | unused |
| Bar Body Size | .5 | float · min .5 · max .9 · step .1 | bigbar |
| Period for bar size average | 10 | int | barsizeavg |
| Big Size Avg Mult to determine Big Bar | 2 | int · step .2 | bigbar |
| Enter trade after confirmation bar | true | bool | BUY 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 | 3 | int · step .1 | LL HH |
| ATR Length | 14 | int | ATR |
| ATR Multiple | 4 | int · step .1 | ATR |
| Take Profit Risk Reward Ratio | 1 | int · step .1 | tp stp ATRtp ATRstp |
| Trailing Stop | false | bool | exit TP & SL SL SSL |
| Strategy SL/TP Mult | 1 | int · step .1 | LongStop ShortStop StratTP StratSTP |
| Allow Direct Position Reverse | true | bool | entry long entry short entry long entry short entry long entry short entry long entry short line 80 line 87 |
| Reverse Trades | false | bool | line 79 |
What it calculates
- Lowest (
lowest,ta.lowestin v5)Swing Point Lookback (10)LL · line 43 - Highest (
highest,ta.highestin v5)Swing Point Lookback (10)HH · line 44 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, LL, 0LL_price · line 45 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, HH, 0HH_price · line 46 - ATR (
atr,ta.atrin v5)ATR Length (14)ATR · line 52 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRLong, 0ATRLongStop · line 55 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRShort, 0ATRShortStop · line 56 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, barsize, 0LongStop · line 69 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, barsize, 0ShortStop · line 70 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, barsize, 0StratTP · line 71 - Valuewhen (
valuewhen,ta.valuewhenin 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | SELL and strategy.position_size == 0 | On | 81 |
| Open short short | BUY and strategy.position_size == 0 | On | 82 |
| Open long long | SELL | On | 84 |
| Open short short | BUY | On | 85 |
| Open long long | BUY and strategy.position_size == 0 | On | 88 |
| Open short short | SELL and strategy.position_size == 0 | On | 89 |
| Open long long | BUY | On | 91 |
| Open short short | SELL | On | 92 |
| Exit TP & SL stop and limit | i_SL | On | 118 |
| Exit TP & SL stop and limit | i_SL | On | 119 |
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 | −56.6% | +102.5% | 13 | 31% | 0.36 | 57.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −22.3% | +5.5% | 21 | 48% | 0.44 | 30.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −76.8% | +9.8% | 11 | 27% | 0.13 | 84.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −23.1% | +8.4% | 17 | 41% | 0.45 | 30.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +142.3% | +16.7% | 5 | 60% | 31.19 | 36.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.0% | +21.5% | 16 | 63% | 1.02 | 23.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +20.4% | +148.3% | 10 | 70% | 1.34 | 40.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.8% | +17.1% | 14 | 57% | 1.09 | 15.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 4 | 50% | −$1,674.66 |
| Sideways market | 6 | 33% | −$1,437.16 |
| Falling market | 3 | 0% | −$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.
All 13 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 1 Mar 2024 61,131.00 | 11 Mar 2024 70,598.40 | 10 | −$1,556.70 |
| short | 17 May 2024 65,235.20 | 26 Jun 2024 61,806.00 | 40 | $437.08 |
| long | 26 Jun 2024 61,806.00 | 5 Aug 2024 53,369.50 | 40 | −$1,218.75 |
| short | 13 Nov 2024 87,952.00 | 5 Dec 2024 103,303.00 | 22 | −$1,343.37 |
| long | 28 Feb 2025 84,708.60 | 8 May 2025 102,118.00 | 69 | $1,292.43 |
| short | 10 May 2025 102,972.00 | 7 Jun 2025 104,288.00 | 28 | −$103.39 |
| long | 7 Jun 2025 104,288.00 | 10 Jul 2025 115,327.00 | 33 | $788.32 |
| long | 27 Sep 2025 109,643.00 | 2 Oct 2025 118,879.00 | 5 | $691.60 |
| long | 6 Nov 2025 103,885.00 | 20 Nov 2025 86,118.30 | 14 | −$1,542.99 |
| long | 3 Dec 2025 91,277.90 | 31 Jan 2026 76,846.20 | 59 | −$1,182.00 |
| long | 7 Feb 2026 70,580.30 | 27 Feb 2026 67,485.20 | 20 | −$279.40 |
| short | 27 Feb 2026 67,485.20 | 4 May 2026 79,656.50 | 66 | −$1,084.26 |
| short | 23 Aug 2026 77,074.90 | 21 Sep 2026 85,762.40 | 29 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Big Bar Strategy this page | — | v4 strategy | −56.6% | 13 | 57.1% |
| Positive Bars - Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −40.3% | 7 | 54.7% |
| 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 37 ms | With a workaround 1,000 bars in 101 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/// © 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)