```
# same_hiorlo_01f
#Micro Double Top/Micro Double Bottom
# find bars of same highs or same lows
def na = Double.NaN;
def bn = barnumber();
input tick_factor = 1;
def ts = TickSize();
def t = (tick_factor * ts);
addlabel(1, " ", color.black);
addlabel(1, ts + " ticksize", color.yellow);
addlabel(1, tick_factor + " tick factor", color.yellow);
addlabel(1, t + " +- tolerance", color.yellow);
def n = 100;
def big = 99999;
#-------------------
# top lines
def topcnt2 = fold i1 = 1 to n
with p1 = 0
while (high <= (getvalue(high, -i1) + (tick_factor * TickSize() )) and high >= (getvalue(high, -i1) - (tick_factor * TickSize() )))
do p1 + 1;
def topcnt = if topcnt2 > 0 then topcnt2 + 1 else 0;
# down counter
def topcntdwn = if bn == 1 then 0
else if topcntdwn[1] <= 1 then topcnt
else if topcntdwn[1] > 0 then topcntdwn[1] - 1
else 0;
# find max of group of bars
def toplvl = if topcntdwn[0] > topcntdwn[1] then
(fold i2 = 0 to topcnt
with p2
do max(p2, getvalue(high, -i2)))
else if topcntdwn[1] >= 2 then toplvl[1]
else 0;
#---------------------------------
# bottom lines
def botcnt2 = fold i3 = 1 to n
with p3 = 0
while (low <= (getvalue(low, -i3) + (tick_factor * TickSize() )) and low >= (getvalue(low, -i3) - (tick_factor * TickSize() )))
do p3 + 1;
def botcnt = if botcnt2 > 0 then botcnt2 + 1 else 0;
# down counter
def botcntdwn = if bn == 1 then 0
else if botcntdwn[1] <= 1 then botcnt
else if botcntdwn[1] > 0 then botcntdwn[1] - 1
else 0;
# find min of group of bars
def botlvl = if botcntdwn[0] > botcntdwn[1] then
(fold i4 = 0 to botcnt
with p4 = big
do min(p4, getvalue(low, -i4)))
else if botcntdwn[1] >= 2 then botlvl[1]
else 0;
#-----------------------
def y = (0.5 * ts);
plot ztop = if toplvl > 0 then toplvl + y else na;
ztop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ztop.SetDefaultColor(Color.cyan);
ztop.setlineweight(1);
plot zbot = if botlvl > 0 then botlvl - y else na;
zbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zbot.SetDefaultColor(Color.yellow);
zbot.hidebubble();
#--------------------
input test1_topnumbers = no;
addchartbubble(test1_topnumbers, low*0.999,
topcnt + " cnt\n" +
topcntdwn + " cntd\n" +
toplvl + " max\n"
, color.yellow, no);
input test2_botnumbers = no;
addchartbubble(test2_botnumbers, low*0.999,
botcnt + " cnt\n" +
botcntdwn + " cntd\n" +
botlvl + " min\n"
, color.yellow, no);
#
```