Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Inside Bar Strategy w- SL

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. 17 settings; defaults include Strategy Direction 0, # Of Inside Bars in pattern 1 and MA Length 65.

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 Inside Bar Strategy w- SL repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
How did Inside Bar Strategy w- SL do on BTCUSDT 1D with default settings?
−61.27%
From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Inside Bar Strategy w- SL 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 Inside Bar Strategy w- SL use a stop loss?
Yes
strategy.exit sets a stop on line 154, 155.
Does Inside Bar Strategy w- SL run in Zeal Terminal?
Yes
It compiles in 44 ms and runs 1,000 bars in 103 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • 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 (17)
50,000100,000150,000AprJulOct2025AprJulOct2026AprJulOct$4,193$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.
Net profit
−61.27%
−$6,126.87
Buy and hold
+102.5%
same period
Closed trades
25
4 won · 21 lost
Profitable
16.0%
of closed trades
Profit factor
0.45
gross profit ÷ gross loss
Max drawdown
64.96%
−$6,880.04

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 117, 118, 120, 121, 124, 125, 127, 128, 154, 155. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 109

    transp = on line 109, 110. v5 folds the transparency into the colour with color.new(c, transp).

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, sma → ta.sma, barssince → ta.barssince.
  • 10 strategy calls use the when = argument (line 117, 118, 120, 121, 124, 125, 127, 128, 154, 155). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 19: //@version=4 → //@version=5
  • Line 28: input(type = input.integer) → input.int()
  • Line 32: input(type = input.integer) → input.int()
  • Line 51: lowest → ta.lowest
  • Line 52: highest → ta.highest
  • Line 53: valuewhen → ta.valuewhen
14 more edits
  • Line 54: valuewhen → ta.valuewhen
  • Line 60: atr → ta.atr
  • Line 63: valuewhen → ta.valuewhen
  • Line 64: valuewhen → ta.valuewhen
  • Line 70: valuewhen → ta.valuewhen
  • Line 71: valuewhen → ta.valuewhen
  • Line 75: sma → ta.sma
  • Line 76: sma → ta.sma
  • Line 79: barssince → ta.barssince
  • Line 80: barssince → ta.barssince
  • Line 109: transp = 100 removed: the call sets no colour to fold it into, so its default colour loses the transparency
  • Line 110: transp = 100 removed: the call sets no colour to fold it into, so its default colour loses the transparency
  • Line 134: valuewhen → ta.valuewhen
  • Line 146: valuewhen → ta.valuewhen
⋯// © tweakerID-//@version=4+//@version=5strategy("Inside Bar Strategy w/ SL", ⋯     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-------------------")  -i_NBars = input(defval=1, type=input.integer, title="# Of Inside Bars in pattern", options=[1, 2, 3, 4])+i_NBars = input.int(defval=1, title="# Of Inside Bars in pattern", options=[1, 2, 3, 4])i_BarsDirection = input(false, title="Only trade using complete bullish or bearish patterns")⋯// 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 ⋯// Strategy Stop-float LongStop = valuewhen(bought,low[1],0)*(1-i_PercIncrement)+float LongStop = ta.valuewhen(bought,low[1],0)*(1-i_PercIncrement)-float ShortStop = valuewhen(bought,high[1],0)*(1+i_PercIncrement)+float ShortStop = ta.valuewhen(bought,high[1],0)*(1+i_PercIncrement)float StratTP = na⋯/////////////////////// STRATEGY LOGIC /////////////////////////////////////////-MAFilter=close > sma(close, i_MALen)+MAFilter=close > ta.sma(close, i_MALen)-plot(i_MAFilter ? sma(close, i_MALen) : na)+plot(i_MAFilter ? ta.sma(close, i_MALen) : na)bullBar=close > openbearBar=close < open-contbullBar=barssince(not bullBar) >= (i_NBars+1)+contbullBar=ta.barssince(not bullBar) >= (i_NBars+1)-contbearBar=barssince(not bearBar) >= (i_NBars+1)+contbearBar=ta.barssince(not bearBar) >= (i_NBars+1)InsideBar(NBars) =>⋯//Debugging Plots-plot(contbullBar ? 1:0, transp=100, title="contbullBar")+plot(contbullBar ? 1:0, title="contbullBar")-plot(contbearBar ? 1:0, transp=100, title="contbearBar")+plot(contbearBar ? 1:0, title="contbearBar")//Trading Inputs⋯//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 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 31: input() → input.bool()
  • Line 33: input() → input.bool()
  • Line 34: input() → input.bool()
  • Line 35: input() → input.int()
  • Line 37: input() → input.bool()
  • Line 39: input() → input.bool()
19 more edits
  • Line 40: input() → input.string()
  • Line 41: input() → input.int()
  • Line 42: input() → input.int()
  • Line 43: input() → input.int()
  • Line 44: input() → input.int()
  • Line 45: input() → input.int()
  • Line 46: input() → input.bool()
  • Line 112: input() → input.bool()
  • Line 113: input() → input.bool()
  • Line 117: when = SELL and strategy.position_size == 0 → if block
  • Line 118: when = BUY and strategy.position_size == 0 → if block
  • Line 120: when = SELL → if block
  • Line 121: when = BUY → if block
  • Line 124: when = BUY and strategy.position_size == 0 → if block
  • Line 125: when = SELL and strategy.position_size == 0 → if block
  • Line 127: when = BUY → if block
  • Line 128: when = SELL → if block
  • Line 154: when = i_SL → if block
  • Line 155: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------")  +title1=input.bool(true, "-----------------Strategy Inputs-------------------")  i_NBars = input.int(defval=1, title="# Of Inside Bars in pattern", options=[1, 2, 3, 4])-i_BarsDirection = input(false, title="Only trade using complete bullish or bearish patterns")+i_BarsDirection = input.bool(false, title="Only trade using complete bullish or bearish patterns")-i_MAFilter = input(true, title="Use MA Trend Filter")+i_MAFilter = input.bool(true, title="Use MA Trend Filter")-i_MALen = input(65, title="MA Length")+i_MALen = input.int(65, title="MA Length")/////////////////////// 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=1, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.int(defval=1, 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(5, step=.1, title="ATR Multiple")+i_ATRMult = input.int(5, step=.1, title="ATR Multiple")-i_TPRRR = input(2, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.int(2, 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⋯//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: 25 before, 63 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.

⋯// © tweakerID-//@version=5+//@version=6strategy("Inside Bar Strategy w/ SL", ⋯

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 29
-----------------Strategy Inputs-------------------trueboolunused
# Of Inside Bars in pattern1int (written input.integer) · options [1, 2, 3, 4]contbullBar contbearBar insideBar
Only trade using complete bullish or bearish patternsfalseboolbullInsideBar bearInsideBar
Use MA Trend FiltertrueboolbullInsideBar bearInsideBar plot
MA Length65intMAFilter plot
-----------------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 Increment1int · step .1LL HH LongStop ShortStop
ATR Length14intATR
ATR Multiple5int · step .1ATR
Take Profit Risk Reward Ratio2int · step .1tp stp ATRtp ATRstp
Trailing Stopfalseboolexit TP & SL SL SSL
Allow Direct Position Reversetrueboolentry long entry short entry long entry short entry long entry short entry long entry short line 116 line 123
Reverse Tradesfalseboolline 115

What it calculates

  • Lowest (lowest, ta.lowest in v5)Swing Point Lookback (10)LL · line 51
  • Highest (highest, ta.highest in v5)Swing Point Lookback (10)HH · line 52
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, LL, 0LL_price · line 53
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, HH, 0HH_price · line 54
  • ATR (atr, ta.atr in v5)ATR Length (14)ATR · line 60
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, ATRLong, 0ATRLongStop · line 63
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, ATRShort, 0ATRShortStop · line 64
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, low[1], 0LongStop · line 70
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, high[1], 0ShortStop · line 71

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 72 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 == 0On117
Open short shortBUY and strategy.position_size == 0On118
Open long longSELLOn120
Open short shortBUYOn121
Open long longBUY and strategy.position_size == 0On124
Open short shortSELL and strategy.position_size == 0On125
Open long longBUYOn127
Open short shortSELLOn128
Exit TP & SL stop and limiti_SLOn154
Exit TP & SL stop and limiti_SLOn155

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.

5/5trades 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−61.3%+102.5%2516%0.4565.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+6.2%+5.5%1937%1.1914.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−9.2%+9.8%1833%0.9175.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−1.3%+8.4%2631%0.9831.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−76.8%+16.7%2232%0.2985.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+44.6%+21.5%2045%2.1516.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−22.7%+148.3%1844%0.8151.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−39.5%+17.1%2719%0.2442.2%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 market813%−$2,958.65
Sideways market1323%−$1,288.93
Falling market40%−$1,877.74

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

How bad could the drawdown be?

77.8%

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

0%89%
All 25 trades
SideEntryExitBarsP&L
short30 Mar 2024 69,850.5015 Apr 2024 65,661.9016$591.67
long15 Apr 2024 65,661.9027 Apr 2024 63,770.0012−$313.50
short27 Apr 2024 63,770.0025 May 2024 68,550.0028−$778.95
long25 May 2024 68,550.0020 Jun 2024 64,974.4026−$502.92
short20 Jun 2024 64,974.4029 Jul 2024 68,249.9039−$460.90
long29 Jul 2024 68,249.905 Aug 2024 55,587.807−$1,589.80
short10 Aug 2024 60,838.0025 Aug 2024 64,157.0015−$384.47
long25 Aug 2024 64,157.001 Sep 2024 58,974.007−$535.11
short1 Sep 2024 58,974.0022 Sep 2024 63,349.0021−$452.04
long22 Sep 2024 63,349.0011 Nov 2024 85,339.9050$1,929.83
long7 Dec 2024 99,740.8012 Jan 2025 94,600.0036−$392.45
short12 Jan 2025 94,600.0019 Jan 2025 104,556.007−$754.43
long19 Jan 2025 104,556.005 Feb 2025 97,763.1017−$417.97
short5 Feb 2025 97,763.1014 May 2025 104,104.0098−$390.08
long14 May 2025 104,104.0015 Sep 2025 115,268.00124$590.43
short15 Sep 2025 115,268.0021 Sep 2025 115,686.006−$27.16
long21 Sep 2025 115,686.0028 Sep 2025 109,636.007−$324.40
short28 Sep 2025 109,636.003 Oct 2025 122,543.005−$686.26
long5 Oct 2025 122,391.0010 Oct 2025 110,121.005−$515.09
short12 Oct 2025 110,644.005 Feb 2026 63,352.70116$1,956.65
short8 Feb 2026 69,289.4024 Apr 2026 78,257.5075−$852.10
long24 Apr 2026 78,257.503 Jun 2026 65,676.0040−$919.23
short7 Jun 2026 60,884.609 Aug 2026 64,962.6063−$323.42
long9 Aug 2026 64,962.6013 Aug 2026 63,480.004−$105.05
short13 Aug 2026 63,480.0020 Aug 2026 70,274.907−$468.57

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
Inside Bar Strategy w- SL this page—v4 strategy−61.3%2565.0%
Positive Bars - Strategy by tweakerIDlowest highest valuewhen atrv4 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
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 44 msYes 1,000 bars in 103 msNot measured
PineTSNo v5 and v6 only—Not measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. 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/// From "Day Trading Cryptocurrency // Strategies, Tactics, Mindset, and Tools Required To Build Your // New Income Stream"// by Phil C. Senior// "Inside bars are a two -bar pattern. They can indicate either a continuation of the // existing move or a reversal. A continuation occurs when there is no significant // support or resistance level in sight, while a reversal occurs close to a strong sup- // port or resistance level...// ...A lot of traders are aware of inside bars but few manage to make money with // them. Why is this so? It goes back to interpreting price action. A lot of traders look // to trade in geometric ways. What I mean is that they search for fancy shapes on a // chart and think that this is what represents true price action. // This is not the case. A shape is just a shape. The formation by itself means // nothing unless underlying order flow backs it up. This is why it’s extremely impor- // tant that you look for inside bars when a trend is already in place. The best place to // look for them is in the beginning of trends."// © tweakerID//@version=4strategy("Inside Bar Strategy w/ SL",      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-------------------")  i_NBars = input(defval=1, type=input.integer, title="# Of Inside Bars in pattern", options=[1, 2, 3, 4])i_BarsDirection = input(false, title="Only trade using complete bullish or bearish patterns")i_MAFilter = input(true, title="Use MA Trend Filter")i_MALen = input(65, title="MA Length")/////////////////////// 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=1, step=.1, title="Swing Point SL Perc Increment")*0.01i_ATR = input(14, title="ATR Length")i_ATRMult = input(5, step=.1, title="ATR Multiple")i_TPRRR = input(2, 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 Stopfloat LongStop = valuewhen(bought,low[1],0)*(1-i_PercIncrement)float ShortStop = valuewhen(bought,high[1],0)*(1+i_PercIncrement)float StratTP = nafloat StratSTP = na/////////////////////// STRATEGY LOGIC /////////////////////////////////////////MAFilter=close > sma(close, i_MALen)plot(i_MAFilter ? sma(close, i_MALen) : na)bullBar=close > openbearBar=close < opencontbullBar=barssince(not bullBar) >= (i_NBars+1)contbearBar=barssince(not bearBar) >= (i_NBars+1)InsideBar(NBars) =>    Inside1Bar=high < high[1] and low > low[1]     Inside2Bar=high < high[2] and low > low[2] and Inside1Bar    Inside3Bar=high < high[3] and low > low[3] and Inside1Bar and Inside2Bar    Inside4Bar=high < high[4] and low > low[4] and Inside1Bar and Inside2Bar and Inside3Bar    if NBars == 1        inside1Bar=Inside1Bar        [inside1Bar]    else if NBars == 2        inside2Bar=Inside2Bar        [inside2Bar]    else if NBars == 3        inside3Bar=Inside3Bar           [inside3Bar]    else if NBars == 4        inside4Bar=Inside4Bar        [inside4Bar]    else        [na][insideBar] = InsideBar(i_NBars)     bullInsideBar=bar_index > 40 and insideBar and bullBar      and (i_BarsDirection ? contbullBar : true) and (i_MAFilter ? MAFilter : true)bearInsideBar=bar_index > 40 and insideBar and bearBar      and (i_BarsDirection ? contbearBar : true) and (i_MAFilter ? not MAFilter : true)BUY = bullInsideBarSELL = bearInsideBar//Debugging Plotsplot(contbullBar ? 1:0, transp=100, title="contbullBar")plot(contbearBar ? 1:0, transp=100, title="contbearBar")//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)