here is a modified version of your study,
..it finds inside bars and outside bars , of 1 and 2 bars.
..inside bars are drawn with cyan , outside bars are drawn with yellow.
..a small arrow is drawn on the big candle. cyan up for inside. yellow down for outside
..it draws lines from the big candle.
..patterns with 2 small bars have a triangle drawn on big candle.
the 2 formulas, insidebar and outsidebar, remove the same, smaller patterns within a larger one.
Code:
# inside_outside_01
# https://usethinkscript.com/threads/inside-outside-bar.12396/
# inside bar and outside bar code,
def na = double.nan;
def price = close;
# inside bar - a big candle and smaller candles after it
def inside1 = high > high[-1] and low < low[-1];
def inside2 = inside1 and high > high[-2] and low < low[-2];
# outside bar - a big candle with smaller candles before it
def outside1 = high > high[1] and low < low[1];
def outside2 = outside1 and high > high[2] and low < low[2];
# remove small insides within larger insides
def insidebar = if inside2[1] then 0 else if inside2 then 2 else if inside1 then 1 else 0;
# remove small outsides within larger outsides
def outsidebar = if outside2[-1] then 0 else if outside2 then 2 else if outside1 then 1 else 0;
input show_small_arrows = yes;
# inside shapes above candles, up wedge
plot zin = if !show_small_arrows then 0 else insidebar;
zin.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zin.SetDefaultColor(Color.cyan);
zin.setlineweight(2);
zin.hidebubble();
# outside shapes below candles, down wedge
plot zout = if !show_small_arrows then 0 else outsidebar;
zout.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zout.SetDefaultColor(Color.yellow);
zout.setlineweight(2);
zout.hidebubble();
plot inside_top =
if insidebar[0] > 0 then high[0]
else if insidebar[1] > 0 then high[1]
else if insidebar[2] > 1 then high[2]
else na;
plot inside_bot =
if insidebar[0] > 0 then low[0]
else if insidebar[1] > 0 then low[1]
else if insidebar[2] > 1 then low[2]
else na;
inside_top.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_top.SetDefaultColor(Color.cyan);
inside_top.hidebubble();
inside_bot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_bot.SetDefaultColor(Color.cyan);
inside_bot.hidebubble();
plot outside_top =
if outsidebar[0] > 0 then high[0]
else if outsidebar[-1] > 0 then high[-1]
else if outsidebar[-2] > 1 then high[-2]
else na;
plot outside_bot =
if outsidebar[0] > 0 then low[0]
else if outsidebar[-1] > 0 then low[-1]
else if outsidebar[-2] > 1 then low[-2]
else na;
outside_top.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_top.SetDefaultColor(Color.yellow);
outside_top.hidebubble();
outside_bot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_bot.SetDefaultColor(Color.yellow);
outside_bot.hidebubble();
input show_double_shapes = yes;
def vert = 0.006;
#plot y1 = if inside1 then high*1.01 else na;
plot y1 = if show_double_shapes and inside2 then high*(1+vert) else na;
y1.SetPaintingStrategy(PaintingStrategy.triangles);
y1.SetDefaultColor(Color.cyan);
y1.setlineweight(4);
y1.hidebubble();
#plot y2 = if inside2 then high*1.02 else na;
plot y2 = if show_double_shapes and outside2 then low*(1-vert) else na;
y2.SetPaintingStrategy(PaintingStrategy.triangles);
y2.SetDefaultColor(Color.yellow);
y2.setlineweight(4);
y2.hidebubble();
#