finding outside bars and inside bars, with various quantities of smaller bars
here are 2 studies for finding, outside bars and inside bars
draws horizontal lines during the range of bars
can pick a minimum quantity of smaller bars
will find smaller x bars, within larger x bar ranges
can pick wicks or body
uses a loop to find the smaller bars, (up to 100)
outside bar
TSLA 2min
inside bars
AAPL 2min
outside bar
. a larger bar , with smaller bars before it
https://www.newtraderu.com/2021/10/29/outside-bar-candlestick-pattern/
inside bar
. a larger bar , followed by smaller bars
https://www.newtraderu.com/2021/12/01/inside-candle-pattern/
-------------------------
i was reading another post and part of the rules included finding inside bars and outside bars...
and i got off on a tangent and made these
-------------------------
outside bars
--------------------------
inside bars
here are 2 studies for finding, outside bars and inside bars
draws horizontal lines during the range of bars
can pick a minimum quantity of smaller bars
will find smaller x bars, within larger x bar ranges
can pick wicks or body
uses a loop to find the smaller bars, (up to 100)
outside bar
TSLA 2min
inside bars
AAPL 2min
outside bar
. a larger bar , with smaller bars before it
https://www.newtraderu.com/2021/10/29/outside-bar-candlestick-pattern/
inside bar
. a larger bar , followed by smaller bars
https://www.newtraderu.com/2021/12/01/inside-candle-pattern/
-------------------------
i was reading another post and part of the rules included finding inside bars and outside bars...
and i got off on a tangent and made these
-------------------------
outside bars
Code:
# outside_bars_00_wickbody_engulf
#----------------
# halcyonguy
# 23-04-03
# find outside bars, can pick a minimum quantity
# find smaller outside bars, within larger outside bar ranges
# can pick wicks or body
#----------------
# outside bar , engulfing
# previous bars are smaller than the current bar
def na = double.nan;
def bn = barnumber();
def o = open;
def h = high;
def l = low;
def c = close;
#def barup = (c > o);
DefineGlobalColor("cout", color.cyan);
#GlobalColor("cout")
input minimum_engulfed_bars = 1;
input show_engulfed_count_bubbles = yes;
input show_engulfed_count_values_below = yes;
input draw_a_box_around_outside_bar = yes;
input show_horizontal_lines = yes;
input show_outside_bars_within_larger_range = yes;
input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
highx = h;
lowx = l;
case "body":
highx = max(o, c);
lowx = min(o, c);
}
# count how many previous bars are smaller than the current bar
def loop1 = 100;
def outcnt1 = fold k = 1 to loop1
with p
while (highx >= getvalue(highx, k) and lowx <= getvalue(lowx, k))
do p + 1;
# enable engulfing bars with enough smaller bars
def outcnt2 = if outcnt1 >= minimum_engulfed_bars then outcnt1 else 0;
def outbar = outcnt2 > 0 ;
# skip over smaller engulfed ranges
# find first bar of engulfed range
# look ahead for biggest future outside bar,
# when the future engulfed bar qty is the same as the offset to it, then keep offset , j
def o_off = fold j = 1 to loop1
with q
do if getvalue(outcnt2, -j) == j then j else q;
# first bar of a range. when the future engulfed bar qty is the same as the offset to that bar
def rng1 = if o_off > 0 and (o_off == getvalue(outcnt2, -o_off)) then 1 else 0;
# count down the bars in the outside range , cnt+1 to 1, from left to right
def outcountdown = if bn == 1 then 0
else if outcountdown[1] <= 1 and rng1 then o_off + 1
else if outcountdown[1] > 0 then (outcountdown[1] - 1)
else 0;
# line levels
def ohi = if bn == 1 then 0
else if outcountdown[1] <= 1 and rng1 then getvalue(highx, -o_off)
else if outcountdown > 0 then ohi[1]
else 0;
def olo = if bn == 1 then 0
else if outcountdown[1] <= 1 and rng1 then getvalue(lowx, -o_off)
else if outcountdown > 0 then olo[1]
else 0;
plot zhi = if show_horizontal_lines and ohi > 0 then ohi else na;
plot zlo = if show_horizontal_lines and olo > 0 then olo else na;
zhi.SetDefaultColor(GlobalColor("cout"));
zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi.hidebubble();
zlo.SetDefaultColor(GlobalColor("cout"));
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.hidebubble();
# mark outside bars, that are within bigger outside bar ranges
def w = (show_outside_bars_within_larger_range and outbar and outcountdown > 1);
plot zw3 = w;
zw3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zw3.SetDefaultColor(GlobalColor("cout"));
zw3.setlineweight(2);
zw3.hidebubble();
plot zw4 = w;
zw4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
zw4.SetDefaultColor(GlobalColor("cout"));
zw4.setlineweight(2);
zw4.hidebubble();
# show engulfed count in a bubble
def yfactor = 0.001;
def yo = l * (1 - yfactor);
addchartbubble(show_engulfed_count_bubbles and outbar and outcountdown == 1, yo, outcnt2, GlobalColor("cout"), no);
# show engulfed count values below
plot z2 = if show_engulfed_count_values_below and outcountdown == 1 then outcnt2 else na;
z2.SetPaintingStrategy(PaintingStrategy.VALUES_below);
z2.SetDefaultColor(GlobalColor("cout"));
# draw box around inside bar
# hollow - open = high , close = low
def o1 = if draw_a_box_around_outside_bar and outcountdown == 1 then h * (1 + (yfactor/1)) else na;
def c1 = if draw_a_box_around_outside_bar and outcountdown == 1 then l * (1 -(yfactor/1)) else na;
AddChart(growcolor = GlobalColor("cout"), high = o1, low = c1, open = c1, close = o1, type = ChartType.CANDLE);
#----------------------------------
# test stuff
addchartbubble(0, yo,
outcnt1 + "\n" +
outcnt2 + "\n" +
o_off + "\n" +
getvalue(outcnt2, -o_off) + "\n" +
outcountdown + "\n" +
rng1
, (if rng1 then color.yellow else color.gray), no);
#
--------------------------
inside bars
Code:
# inside_bars_00_wickbody
#----------------
# halcyonguy
# 23-04-03
# find inside bars, can pick a minimum quantity
# find smaller inside bars, within larger inside bar ranges
# can pick wicks or body
#----------------
# inside bars
# count smaller future bars, after a big bar
def bn = BarNumber();
def na = Double.NaN;
def o = open;
def h = high;
def l = low;
def c = close;
#def barup = (c > o);
DefineGlobalColor("c1", color.yellow);
# GlobalColor("c1")
input minimum_inside_bars = 1;
input show_inside_count_bubbles = yes;
input show_inside_count_values_above = no;
input draw_a_box_around_inside_bar = yes;
input show_horizontal_lines = yes;
input show_inside_bars_within_larger_range = yes;
input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
highx = h;
lowx = l;
case "body":
highx = max(o, c);
lowx = min(o, c);
}
def loop1 = 100;
# count how many future bars are smaller than the current bar
def incnt1 = fold k = 1 to loop1
with p
while (highx >= GetValue(highx, -k) and lowx <= GetValue(lowx, -k))
do p + 1;
def incnt2 = if incnt1 >= minimum_inside_bars then incnt1 else 0;
# count down the bars in the inside range , cnt+1 to 1
def incountdown = if bn == 1 then 0
else if incountdown[1] <= 1 and incnt2 > 0 then incnt2+1
else if incountdown[1] > 0 then (incountdown[1] - 1)
else 0;
# ignore future mother bars, within prev inside bar range
# if countdown > 0 then ignore
def skip_in = if incnt2 > 0 and incountdown > 0 and incountdown[1] > 1 then 1 else 0;
def skipin = (show_inside_bars_within_larger_range and skip_in);
plot zskp1 = skipin;
zskp1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zskp1.SetDefaultColor(GlobalColor("c1"));
zskp1.setlineweight(2);
zskp1.hidebubble();
plot zskp2 = skipin;
zskp2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
zskp2.SetDefaultColor(GlobalColor("c1"));
zskp2.setlineweight(2);
zskp2.hidebubble();
def yoff = 0.001;
def y6 = h * (1 + yoff);
AddChartBubble(show_inside_count_bubbles and incountdown[1] <= 1 and incountdown > 0 , y6, incnt2 , GlobalColor("c1"), yes);
plot z = if show_inside_count_values_above and incnt2 > 0 and !skipin then incnt2 else na;
z.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
z.SetDefaultColor(GlobalColor("c1"));
# draw box around inside bar
# hollow - open = high , close = low
def o1 = if draw_a_box_around_inside_bar and (incountdown[1] <= 1 and incountdown > 0) then h * (1 + (yoff/1)) else na;
def c1 = if draw_a_box_around_inside_bar and (incountdown[1] <= 1 and incountdown > 0) then l * (1 -(yoff/1)) else na;
AddChart(growcolor = GlobalColor("c1"), high = o1, low = c1, open = c1, close = o1, type = ChartType.CANDLE);
# plot horz lines during inside range
def in_hi = if incountdown[1] <= 1 and incountdown > 0 then highx
else if incountdown > 0 then in_hi[1]
else 0;
def in_lo = if incountdown[1] <= 1 and incountdown > 0 then lowx
else if incountdown > 0 then in_lo[1]
else 0;
plot zinhi = if show_horizontal_lines and in_hi > 0 then in_hi else na;
plot zinlo = if show_horizontal_lines and in_lo > 0 then in_lo else na;
zinhi.SetDefaultColor(GlobalColor("c1"));
zinhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zinhi.hidebubble();
zinlo.SetDefaultColor(GlobalColor("c1"));
zinlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zinlo.hidebubble();
#----------------------------
# test stuff
addchartbubble(0, l,
incnt1 + "\n" +
incnt2 + "\n" +
incountdown,
(if incountdown > 0 then color.yellow else color.gray), no);
#
Last edited by a moderator: