# Micro Double Top/Micro Double Bottom

#### bon

##### New member
Can anyone post an indicator that draws a small line/dot when two consecutive bars close with a high or a low at the same price? For example, if two consecutive bars both have a high at 4430.50 can a small line/dot be drawn above those bars? Or if two consecutive bars both have a low of 4429.50 can a small line/dot be drawn beneath those bars?

It would be nice if this indicator had a feature where if it's off by a tick or two the user could select whether it still qualifies. For example, with the "offset" feature turned to 1, if one bar closes with a high at 4430.50 and the next closes with a high at 4430.25, that could still be shown as a double top. No worries if that's too complicated though.

I am trading futures on /MES and this what Al Brooks refers to as a "Micro Double Top" and "Micro Double Bottom."

Here you go.

You're the only person on this forum I've seen reference Al, so that drew my attention. I started with his books years ago and it's invaluable information. Best of luck.

Just a word of caution, this does not quite look correct for a couple reasons.

1. Al does not consider anything but a perfect match a true MDT/MDB. He considers a 1 tick higher/lower top/bottom a 1 tick failure, so it's best to chart only exact MDT/MDBs. If you try to match anything within 1 or 2 ticks you're going to get a lot of bars showing MDTs/MDBs that aren't.

2. Because this study has to look at future bars, it may not draw a line on the first bar that's an MDT/MDB.

It's a start, but you may want to consider tweaking the conditions to get exactly what you want.

Ruby:
``````#DECLARATIONS
declare upper;
declare once_per_bar;

#USER INPUTS
input tickDifferenceAllowed = 1;

#DEFINITIONS
def isMDT =
high == high
or high == high - (tickDifferenceAllowed * TickSize())
or high == high[-1]
or high == high[-1] + (tickDifferenceAllowed * TickSize());

def isMDB =
low == low
or low == low - (tickDifferenceAllowed * TickSize())
or low == low[-1]
or low == low[-1] + (tickDifferenceAllowed * TickSize());

#PLOTS
plot mdt = if isMDT then Min(high, high) else Double.NaN;
plot mdb = if isMDB then Max(low, low) else Double.NaN;;

#FORMATTING
mdt.setdefaultcolor(Color.RED);
mdt.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
mdt.hidetitle();
mdt.hidebubble();

mdb.setdefaultcolor(Color.GREEN);
mdb.SetPaintingStrategy(PaintingStrategy.DASHES);
mdb.hidetitle();
mdb.hidebubble();``````

Last edited:
• bon
Can anyone post an indicator that draws a small line/dot when two consecutive bars close with a high or a low at the same price? For example, if two consecutive bars both have a high at 4430.50 can a small line/dot be drawn above those bars? Or if two consecutive bars both have a low of 4429.50 can a small line/dot be drawn beneath those bars?

It would be nice if this indicator had a feature where if it's off by a tick or two the user could select whether it still qualifies. For example, with the "offset" feature turned to 1, if one bar closes with a high at 4430.50 and the next closes with a high at 4430.25, that could still be shown as a double top. No worries if that's too complicated though.

I am trading futures on /MES and this what Al Brooks refers to as a "Micro Double Top" and "Micro Double Bottom."

find 2+ consecutive bars with the same high price or same low price.
once a line starts, a new grouping can't happen until after the current one.

can choose a tolerance factor, that is multiplied by the ticksize.
...if 0 is chosen, then the prices have to be the same.

i think lines are easier to see if they don't touch the candles so,
...horizontal high lines are drawn slightly above the candles.
...horizontal low lines are drawn slightly below the candles.

labels display the tolerance and ticksize.

i started with armybenders code, but ended up redoing it. his code would draw diagonal lines because of the plot formula.

Code:
``````# 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, 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 then topcnt
else if topcntdwn > 0 then topcntdwn - 1
else 0;

# find max of group of bars
def toplvl = if topcntdwn > topcntdwn then
(fold i2 = 0 to topcnt
with p2
do max(p2, getvalue(high, -i2)))
else if  topcntdwn >= 2 then toplvl
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 then botcnt
else if botcntdwn > 0 then botcntdwn - 1
else 0;

# find min of group of bars
def botlvl = if botcntdwn > botcntdwn then
(fold i4 = 0 to botcnt
with p4 = big
do min(p4, getvalue(low, -i4)))
else if  botcntdwn >= 2 then botlvl
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;
topcnt + " cnt\n" +
topcntdwn + " cntd\n" +
toplvl + " max\n"
, color.yellow, no);

input test2_botnumbers = no;
botcnt + " cnt\n" +
botcntdwn + " cntd\n" +
botlvl + " min\n"
, color.yellow, no);

#``````

tolerance = 0 tolerance = 1 Last edited:
• • MerryDay and bon
Thank you! Exactly what I was looking for... Thank you, Armybender, too.
find 2+ consecutive bars with the same high price or same low price.

can choose a tolerance factor, that is multiplied by the ticksize.
...if 0 is chosen, then the prices have to be the same.

i think lines are easier to see if they don't touch the candles so,
...horizontal high lines are drawn slightly above the candles.
...horizontal low lines are drawn slightly below the candles.

labels display the tolerance and ticksize.

i started with armybenders code, but ended up redoing it. his code would draw diagonal lines because of the plot formula.

Code:
``````# 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, 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 then topcnt
else if topcntdwn > 0 then topcntdwn - 1
else 0;

# find max of group of bars
def toplvl = if topcntdwn > topcntdwn then
(fold i2 = 0 to topcnt
with p2
do max(p2, getvalue(high, -i2)))
else if  topcntdwn >= 2 then toplvl
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 then botcnt
else if botcntdwn > 0 then botcntdwn - 1
else 0;

# find min of group of bars
def botlvl = if botcntdwn > botcntdwn then
(fold i4 = 0 to botcnt
with p4 = big
do min(p4, getvalue(low, -i4)))
else if  botcntdwn >= 2 then botlvl
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;
topcnt + " cnt\n" +
topcntdwn + " cntd\n" +
toplvl + " max\n"
, color.yellow, no);

input test2_botnumbers = no;
botcnt + " cnt\n" +
botcntdwn + " cntd\n" +
botlvl + " min\n"
, color.yellow, no);

#``````

tolerance = 0 tolerance = 1 ### Not the exact question you're looking for?

87k+ Posts
207 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?