How to draw a rectangle based on first "n" candles

blueantz

New member
Looking to draw a rectangle for each trading day between 9.30am to 4.00pm based on the highs and lows of the first n candles. This should be applicable across any time interval

“n” would be an input parameter
Color would be an input parameter
Transparency of color would be an input parameter

Any help would be greatly appreciated
 
There are many good opening range indicators on the forum. Transparency can be set through use of global colours, though ThinkOrSwim doesn't allow us to draw boxes per se, we can plot horizontal lines across the chart and colour between them.

Start with this one perhaps:
https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/

Good luck, and if you can't find something around here that works for what you want, please post what you've tried and why it is deficient (how you would make it different to suit your intentions) and we'll [the community] see what we can do for you.

Happy Trading and welcome to UTS, it's a great place to be.

-mashume
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

There are many good opening range indicators on the forum. Transparency can be set through use of global colours, though ThinkOrSwim doesn't allow us to draw boxes per se, we can plot horizontal lines across the chart and colour between them.

Start with this one perhaps:
https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/

Good luck, and if you can't find something around here that works for what you want, please post what you've tried and why it is deficient (how you would make it different to suit your intentions) and we'll [the community] see what we can do for you.

Happy Trading and welcome to UTS, it's a great place to be.

-mashume
Here's a script that draws boxes as zones instead of lines. It doesn't do what blueantz wants it to do though. Maybe someone here can mash it up with mashume's idea.

Code:
# richard_the_red Jimmy Momo Zones

# This study was inspired by Jimmy Momo reactive candles created by @JamesLeFaith. His idea was to draw resistance lines at the open of the largest candles in the range and use those as the basis of supply/demand zones in multiple time periods. This script draws red (short) & green (long) S/D bars and when supply turns demand and back these zones flip colors as price action moves through them.

# Many thanks to @JamesLeFaith for his expertise and collaboration on this project. Without his input, advice,feedback, and in particular his groundbreaking work on reactive candles, this script wouldn't exist. Many people have tried to create a coherent system of supply and demand but I believe his is the first to deliver on that promise.

# This script © richard_the_red. Reactive candles and the Jimmy Momo trading system are the original creation of Jimmy Momo, https://twitter.com/JamesLeFaith.

#This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl.html

# These zones are not a buy or sell indicator or financial advice, and RTR_Jimmy_Momo_Zones is not a financial advisor.




input show_zones = yes;  #hint show_zones: Turn the colored zone bars off
input number_of_zones = 10; #hint number_of_zones: Max 15, but more zones mean slower performance
def numzones = Min(number_of_zones, 15);

input Show_Stats_Label = no;

input use_range = {default "Chart Range", "Bars", "Days"}; #hint use_range: Normally zones would be drawn on the biggest candle in the chart range, Bars or Days forces zones to the hard-coded range specified instead.
input range = 0; #hint range: How many bars or days to use if "Chart Range" is not selected. Ignored if 'Use Chart' is selected or the range exceeds the chart range.

input Use_Expansive_Zones = no; #hint Use_Expansive_Zones: Draw zones to the previous candle wick even if that's huge and more zones overlap. Defaults to more precise zones.


#input Only_Show_Below = AggregationPeriod.YEAR;
def isShowing = yes;#GetAggregationPeriod() < Only_Show_Below;
def body_standard_deviations = 1.0; #hint body_standard_deviations: How inclusive candle body calculations are. Smaller is more inclusive, 1.0 is default. Don't change this unless you know what you're doing or at least know how to reset to default.
def body_average_range = 6; #hint body_average_range: The lookback range for average body height
def volume_standard_deviations = 0.2; #hint volume_standard_deviations: How inclusive volume is. Lower is more inclusive. 0.2 is default. If you change this it's on you, man. You probably didn't even read this hint in the first place.
def volume_average_range = 100; #hint volume_average_range: Lookback range to see if volume is above average

def debug = no; #hint debug: Don't.


DefineGlobalColor("indicator", CreateColor(249,233,167));
DefineGlobalColor("long", CreateColor(132,138,63));
DefineGlobalColor("short", CreateColor(189,71,30));

def bn = BarNumber();
def lbn_candidate = If (!IsNaN(close[-1]), bn, lbn_candidate[1]);
def lbn = HighestAll(lbn_candidate);
def chart_scale = GetAggregationPeriod() / 1000 / 60; # minutes

def chart_range;
switch (use_range) {
case "Chart Range":
    chart_range = lbn;
case "Bars":
    chart_range = range;
case "Days":
    chart_range = Min(lbn, range * 16 * (60 / chart_scale));
}
def isInChartRange = bn >= lbn - chart_range;


def l = low;
def h = high;
def v = volume;

def bt = Max(close, open);
def bb = Min(close, open);
def gapDown = If (bb[1] > h, bb[1] - bt, 0);
def gapUp = If (bt[1] < l, bb - bt[1], 0);

def bodytop;
def bodybottom;
def c;
if (gapUp > 0) {
    bodytop = bt;
    bodybottom = bt[1];
    c = bodytop;
} else if (gapDown > 0) {
    bodytop = bb[1];
    bodybottom = bb;
    c = bodybottom;
} else {
    bodytop = bt;
    bodybottom = bb;
    c = close;
}
def o = If (bodytop[1] < c, Min(bodytop[1], open), open); # gappy gap

def body = bodytop - bodybottom;

def isG = c > o;
def isR = c < o;

def body_sd = StDev(body, body_average_range);
def isHotBody = body > body_sd[3] * body_standard_deviations;
def vol_sd = StDev(v, volume_average_range);
def isHotVolume = v > vol_sd[3] * volume_standard_deviations;
def isHot = isHotBody && isHotVolume;
def show = isShowing && isHot;





plot dot = if (show, if (isG, bodybottom, bodytop), Double.NaN);
dot.SetPaintingStrategy(PaintingStrategy.DASHES);
dot.SetLineWeight(2);
dot.AssignValueColor(GlobalColor("indicator"));
dot.HideBubble();
dot.HideTitle();

def wtestc = if (Use_Expansive_Zones, c, l);
def wtesto = if (Use_Expansive_Zones, o, h);
def wick_value = if (show,
    if (isG, if (bodytop[1] >= wtestc, l, Min(l[0], l[1])), # green wick is lowest
    if (isR, if (bodybottom[1] <= wtesto, h, Max(h[0], h[1])), # red wick is highest
    Double.NaN)),
Double.NaN);
plot wick = if (wick_value == dot && !isnan(wick_value), wick_value + .01, wick_value); # need to have something if wick is same as dot.
wick.SetPaintingStrategy(PaintingStrategy.DASHES);
wick.SetLineWeight(1);
wick.AssignValueColor(GlobalColor("indicator"));
wick.HideBubble();
wick.HideTitle();




def g1b = If (body >= g1b[1] && isInChartRange, body, g1b[1]); # set largest bar, all others will be shorter
def g1_bn_candidate = If (body == HighestAll(g1b), bn, Double.NaN);
def g1bn = HighestAll(g1_bn_candidate);
def g1_bn_offset = bn - g1bn;
def g1o = if (g1_bn_offset == 0, dot, GetValue(dot, g1_bn_offset));
def g1w = GetValue(wick, g1_bn_offset);
def showcloud1 = show_zones && numzones >= 1 && g1o && bn >= g1bn;
def g1zt = Max(g1o, g1w);
def g1zb = Min(g1o, g1w);
def g1isLong = bodybottom > g1zt;
def g1isInside = (bodybottom < g1zt && !(bodytop < g1zb) or (bodytop > g1zb && !(bodybottom > g1zt)));
def g1useGreen = If (bn == g1bn, isG, If (g1isInside, g1useGreen[1], g1isLong));
def g1g = g1useGreen;
AddCloud( If (showcloud1, If (g1g, g1zt, g1zb), Double.NaN), If (showcloud1, If (g1g, g1zb, g1zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g1bn && debug, high, "1:" + showcloud1 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g2b = If (body >= g2b[1] && body < HighestAll(g1b) && bn != HighestAll(g1bn) && isInChartRange, body, g2b[1]);
def g2_bn_candidate = If (body == HighestAll(g2b), bn, Double.NaN);
def g2bn = HighestAll(g2_bn_candidate);
def g2_bn_offset = bn - g2bn;
def g2o = GetValue(dot, g2_bn_offset);
def g2w = GetValue(wick, g2_bn_offset);
def showcloud2 = show_zones && numzones >= 2 && g2o && bn >= g2bn;
def g2zt = Max(g2o, g2w);
def g2zb = Min(g2o, g2w);
def g2isLong = bodybottom > g2zt;
def g2isInside = (bodybottom < g2zt && !(bodytop < g2zb) or (bodytop > g2zb && !(bodybottom > g2zt)));
def g2useGreen = If (bn == g2bn, isG, If (g2isInside, g2useGreen[1], g2isLong));
def g2g = g2useGreen;
AddCloud( If (showcloud2, If (g2g, g2zt, g2zb), Double.NaN), If (showcloud2, If (g2g, g2zb, g2zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g2bn && debug, high, "2:" + showcloud2 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g3b = If (body >= g3b[1] && body < HighestAll(g2b) && bn != g2bn && isInChartRange, body, g3b[1]);
def g3_bn_candidate = If (body == HighestAll(g3b), bn, Double.NaN);
def g3bn = HighestAll(g3_bn_candidate);
def g3_bn_offset = bn - g3bn;
def g3o = GetValue(dot, g3_bn_offset);
def g3w = GetValue(wick, g3_bn_offset);
def showcloud3 = show_zones && numzones >= 3 && g3o && bn >= g3bn;
def g3zt = Max(g3o, g3w);
def g3zb = Min(g3o, g3w);
def g3isLong = bodybottom > g3zt;
def g3isInside = (bodybottom < g3zt && !(bodytop < g3zb) or (bodytop > g3zb && !(bodybottom > g3zt)));
def g3useGreen = If (bn == g3bn, isG, If (g3isInside, g3useGreen[1], g3isLong));
def g3g = g3useGreen;
AddCloud( If (showcloud3, If (g3g, g3zt, g3zb), Double.NaN), If (showcloud3, If (g3g, g3zb, g3zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g3bn && debug, high, "3:" + showcloud3 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g4b = If (body >= g4b[1] && body < HighestAll(g3b) && bn != g3bn && isInChartRange, body, g4b[1]);
def g4_bn_candidate = If (body == HighestAll(g4b), bn, Double.NaN);
def g4bn = HighestAll(g4_bn_candidate);
def g4_bn_offset = bn - g4bn;
def g4o = GetValue(dot, g4_bn_offset);
def g4w = GetValue(wick, g4_bn_offset);
def showcloud4 = show_zones && numzones >= 4 && g4o && bn >= g4bn;
def g4zt = Max(g4o, g4w);
def g4zb = Min(g4o, g4w);
def g4isLong = bodybottom > g4zt;
def g4isInside = (bodybottom < g4zt && !(bodytop < g4zb) or (bodytop > g4zb && !(bodybottom > g4zt)));
def g4useGreen = If (bn == g4bn, isG, If (g4isInside, g4useGreen[1], g4isLong));
def g4g = g4useGreen;
AddCloud( If (showcloud4, If (g4g, g4zt, g4zb), Double.NaN), If (showcloud4, If (g4g, g4zb, g4zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g4bn && debug, high, "4:" + showcloud4 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g5b = If (body >= g5b[1] && body < HighestAll(g4b) && bn != g4bn && isInChartRange, body, g5b[1]);
def g5_bn_candidate = If (body == HighestAll(g5b), bn, Double.NaN);
def g5bn = HighestAll(g5_bn_candidate);
def g5_bn_offset = bn - g5bn;
def g5o = GetValue(dot, g5_bn_offset);
def g5w = GetValue(wick, g5_bn_offset);
def showcloud5 = show_zones && numzones >= 5 && g5o && bn >= g5bn;
def g5zt = Max(g5o, g5w);
def g5zb = Min(g5o, g5w);
def g5isLong = bodybottom > g5zt;
def g5isInside = (bodybottom < g5zt && !(bodytop < g5zb) or (bodytop > g5zb && !(bodybottom > g5zt)));
def g5useGreen = If (bn == g5bn, isG, If (g5isInside, g5useGreen[1], g5isLong));
def g5g = g5useGreen;
AddCloud( If (showcloud5, If (g5g, g5zt, g5zb), Double.NaN), If (showcloud5, If (g5g, g5zb, g5zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g5bn && debug, high, "5:" + showcloud5 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g6b = If (body >= g6b[1] && body < HighestAll(g5b) && bn != g5bn && isInChartRange, body, g6b[1]);
def g6_bn_candidate = If (body == HighestAll(g6b), bn, Double.NaN);
def g6bn = HighestAll(g6_bn_candidate);
def g6_bn_offset = bn - g6bn;
def g6o = GetValue(dot, g6_bn_offset);
def g6w = GetValue(wick, g6_bn_offset);
def showcloud6 = show_zones && numzones >= 6 && g6o && bn >= g6bn;
def g6zt = Max(g6o, g6w);
def g6zb = Min(g6o, g6w);
def g6isLong = bodybottom > g6zt;
def g6isInside = (bodybottom < g6zt && !(bodytop < g6zb) or (bodytop > g6zb && !(bodybottom > g6zt)));
def g6useGreen = If (bn == g6bn, isG, If (g6isInside, g6useGreen[1], g6isLong));
def g6g = g6useGreen;
AddCloud( If (showcloud6, If (g6g, g6zt, g6zb), Double.NaN), If (showcloud6, If (g6g, g6zb, g6zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g6bn && debug, high, "6:" + showcloud6 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g7b = If (body >= g7b[1] && body < HighestAll(g6b) && bn != g6bn && isInChartRange, body, g7b[1]);
def g7_bn_candidate = If (body == HighestAll(g7b), bn, Double.NaN);
def g7bn = HighestAll(g7_bn_candidate);
def g7_bn_offset = bn - g7bn;
def g7o = GetValue(dot, g7_bn_offset);
def g7w = GetValue(wick, g7_bn_offset);
def showcloud7 = show_zones && numzones >= 7 && g7o && bn >= g7bn;
def g7zt = Max(g7o, g7w);
def g7zb = Min(g7o, g7w);
def g7isLong = bodybottom > g7zt;
def g7isInside = (bodybottom < g7zt && !(bodytop < g7zb) or (bodytop > g7zb && !(bodybottom > g7zt)));
def g7useGreen = If (bn == g7bn, isG, If (g7isInside, g7useGreen[1], g7isLong));
def g7g = g7useGreen;
AddCloud( If (showcloud7, If (g7g, g7zt, g7zb), Double.NaN), If (showcloud7, If (g7g, g7zb, g7zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g7bn && debug, high, "7:" + showcloud7 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g8b = If (body >= g8b[1] && body < HighestAll(g7b) && bn != g7bn && isInChartRange, body, g8b[1]);
def g8_bn_candidate = If (body == HighestAll(g8b), bn, Double.NaN);
def g8bn = HighestAll(g8_bn_candidate);
def g8_bn_offset = bn - g8bn;
def g8o = GetValue(dot, g8_bn_offset);
def g8w = GetValue(wick, g8_bn_offset);
def showcloud8 = show_zones && numzones >= 8 && g8o && bn >= g8bn;
def g8zt = Max(g8o, g8w);
def g8zb = Min(g8o, g8w);
def g8isLong = bodybottom > g8zt;
def g8isInside = (bodybottom < g8zt && !(bodytop < g8zb) or (bodytop > g8zb && !(bodybottom > g8zt)));
def g8useGreen = If (bn == g8bn, isG, If (g8isInside, g8useGreen[1], g8isLong));
def g8g = g8useGreen;
AddCloud( If (showcloud8, If (g8g, g8zt, g8zb), Double.NaN), If (showcloud8, If (g8g, g8zb, g8zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g8bn && debug, high, "8:" + showcloud8 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g9b = If (body >= g9b[1] && body < HighestAll(g8b) && bn != g8bn && isInChartRange, body, g9b[1]);
def g9_bn_candidate = If (body == HighestAll(g9b), bn, Double.NaN);
def g9bn = HighestAll(g9_bn_candidate);
def g9_bn_offset = bn - g9bn;
def g9o = GetValue(dot, g9_bn_offset);
def g9w = GetValue(wick, g9_bn_offset);
def showcloud9 = show_zones && numzones >= 9 && g9o && bn >= g9bn;
def g9zt = Max(g9o, g9w);
def g9zb = Min(g9o, g9w);
def g9isLong = bodybottom > g9zt;
def g9isInside = (bodybottom < g9zt && !(bodytop < g9zb) or (bodytop > g9zb && !(bodybottom > g9zt)));
def g9useGreen = If (bn == g9bn, isG, If (g9isInside, g9useGreen[1], g9isLong));
def g9g = g9useGreen;
AddCloud( If (showcloud9, If (g9g, g9zt, g9zb), Double.NaN), If (showcloud9, If (g9g, g9zb, g9zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g9bn && debug, high, "9:" + showcloud9 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g10b = If (body >= g10b[1] && body < HighestAll(g9b) && bn != g9bn && isInChartRange, body, g10b[1]);
def g10_bn_candidate = If (body == HighestAll(g10b), bn, Double.NaN);
def g10bn = HighestAll(g10_bn_candidate);
def g10_bn_offset = bn - g10bn;
def g10o = GetValue(dot, g10_bn_offset);
def g10w = GetValue(wick, g10_bn_offset);
def showcloud10 = show_zones && numzones >= 10 && g10o && bn >= g10bn;
def g10zt = Max(g10o, g10w);
def g10zb = Min(g10o, g10w);
def g10isLong = bodybottom > g10zt;
def g10isInside = (bodybottom < g10zt && !(bodytop < g10zb) or (bodytop > g10zb && !(bodybottom > g10zt)));
def g10useGreen = If (bn == g10bn, isG, If (g10isInside, g10useGreen[1], g10isLong));
def g10g = g10useGreen;
AddCloud( If (showcloud10, If (g10g, g10zt, g10zb), Double.NaN), If (showcloud10, If (g10g, g10zb, g10zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g10bn && debug, high, "10:" + showcloud10 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g11b = If (body >= g11b[1] && body < HighestAll(g10b) && bn != g10bn && isInChartRange, body, g11b[1]);
def g11_bn_candidate = If (body == HighestAll(g11b), bn, Double.NaN);
def g11bn = HighestAll(g11_bn_candidate);
def g11_bn_offset = bn - g11bn;
def g11o = GetValue(dot, g11_bn_offset);
def g11w = GetValue(wick, g11_bn_offset);
def showcloud11 = show_zones && numzones >= 11 && g11o && bn >= g11bn;
def g11zt = Max(g11o, g11w);
def g11zb = Min(g11o, g11w);
def g11isLong = bodybottom > g11zt;
def g11isInside = (bodybottom < g11zt && !(bodytop < g11zb) or (bodytop > g11zb && !(bodybottom > g11zt)));
def g11useGreen = If (bn == g11bn, isG, If (g11isInside, g11useGreen[1], g11isLong));
def g11g = g11useGreen;
AddCloud( If (showcloud11, If (g11g, g11zt, g11zb), Double.NaN), If (showcloud11, If (g11g, g11zb, g11zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g11bn && debug, high, "11:" + showcloud11 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g12b = If (body >= g12b[1] && body < HighestAll(g11b) && bn != g11bn && isInChartRange, body, g12b[1]);
def g12_bn_candidate = If (body == HighestAll(g12b), bn, Double.NaN);
def g12bn = HighestAll(g12_bn_candidate);
def g12_bn_offset = bn - g12bn;
def g12o = GetValue(dot, g12_bn_offset);
def g12w = GetValue(wick, g12_bn_offset);
def showcloud12 = show_zones && numzones >= 12 && g12o && bn >= g12bn;
def g12zt = Max(g12o, g12w);
def g12zb = Min(g12o, g12w);
def g12isLong = bodybottom > g12zt;
def g12isInside = (bodybottom < g12zt && !(bodytop < g12zb) or (bodytop > g12zb && !(bodybottom > g12zt)));
def g12useGreen = If (bn == g12bn, isG, If (g12isInside, g12useGreen[1], g12isLong));
def g12g = g12useGreen;
AddCloud( If (showcloud12, If (g12g, g12zt, g12zb), Double.NaN), If (showcloud12, If (g12g, g12zb, g12zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g12bn && debug, high, "12:" + showcloud12 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g13b = If (body >= g13b[1] && body < HighestAll(g12b) && bn != g12bn && isInChartRange, body, g13b[1]);
def g13_bn_candidate = If (body == HighestAll(g13b), bn, Double.NaN);
def g13bn = HighestAll(g13_bn_candidate);
def g13_bn_offset = bn - g13bn;
def g13o = GetValue(dot, g13_bn_offset);
def g13w = GetValue(wick, g13_bn_offset);
def showcloud13 = show_zones && numzones >= 13 && g13o && bn >= g13bn;
def g13zt = Max(g13o, g13w);
def g13zb = Min(g13o, g13w);
def g13isLong = bodybottom > g13zt;
def g13isInside = (bodybottom < g13zt && !(bodytop < g13zb) or (bodytop > g13zb && !(bodybottom > g13zt)));
def g13useGreen = If (bn == g13bn, isG, If (g13isInside, g13useGreen[1], g13isLong));
def g13g = g13useGreen;
AddCloud( If (showcloud13, If (g13g, g13zt, g13zb), Double.NaN), If (showcloud13, If (g13g, g13zb, g13zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g13bn && debug, high, "13:" + showcloud13 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g14b = If (body >= g14b[1] && body < HighestAll(g13b) && bn != g13bn && isInChartRange, body, g14b[1]);
def g14_bn_candidate = If (body == HighestAll(g14b), bn, Double.NaN);
def g14bn = HighestAll(g14_bn_candidate);
def g14_bn_offset = bn - g14bn;
def g14o = GetValue(dot, g14_bn_offset);
def g14w = GetValue(wick, g14_bn_offset);
def showcloud14 = show_zones && numzones >= 14 && g14o && bn >= g14bn;
def g14zt = Max(g14o, g14w);
def g14zb = Min(g14o, g14w);
def g14isLong = bodybottom > g14zt;
def g14isInside = (bodybottom < g14zt && !(bodytop < g14zb) or (bodytop > g14zb && !(bodybottom > g14zt)));
def g14useGreen = If (bn == g14bn, isG, If (g14isInside, g14useGreen[1], g14isLong));
def g14g = g14useGreen;
AddCloud( If (showcloud14, If (g14g, g14zt, g14zb), Double.NaN), If (showcloud14, If (g14g, g14zb, g14zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g14bn && debug, high, "14:" + showcloud14 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g15b = If (body >= g15b[1] && body < HighestAll(g14b) && bn != g14bn && isInChartRange, body, g15b[1]);
def g15_bn_candidate = If (body == HighestAll(g15b), bn, Double.NaN);
def g15bn = HighestAll(g15_bn_candidate);
def g15_bn_offset = bn - g15bn;
def g15o = GetValue(dot, g15_bn_offset);
def g15w = GetValue(wick, g15_bn_offset);
def showcloud15 = show_zones && numzones >= 15 && g15o && bn >= g15bn;
def g15zt = Max(g15o, g15w);
def g15zb = Min(g15o, g15w);
def g15isLong = bodybottom > g15zt;
def g15isInside = (bodybottom < g15zt && !(bodytop < g15zb) or (bodytop > g15zb && !(bodybottom > g15zt)));
def g15useGreen = If (bn == g15bn, isG, If (g15isInside, g15useGreen[1], g15isLong));
def g15g = g15useGreen;
AddCloud( If (showcloud15, If (g15g, g15zt, g15zb), Double.NaN), If (showcloud15, If (g15g, g15zb, g15zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g15bn && debug, high, "15:" + showcloud15 + "; dot: " + dot + "; wick: " + wick, color.white, yes);


def dotcount = dotcount[1] + If (isHot, 1, 0);
def zonecount =
  If (!IsNaN(showcloud1), 1, 0)
+ If (!IsNaN(showcloud2), 1, 0)
+ If (!IsNaN(showcloud3), 1, 0)
+ If (!IsNaN(showcloud4), 1, 0)
+ If (!IsNaN(showcloud5), 1, 0)
+ If (!IsNaN(showcloud6), 1, 0)
+ If (!IsNaN(showcloud7), 1, 0)
+ If (!IsNaN(showcloud8), 1, 0)
+ If (!IsNaN(showcloud9), 1, 0)
+ If (!IsNaN(showcloud10), 1, 0)
+ If (!IsNaN(showcloud11), 1, 0)
+ If (!IsNaN(showcloud12), 1, 0)
+ If (!IsNaN(showcloud13), 1, 0)
+ If (!IsNaN(showcloud14), 1, 0)
+ If (!IsNaN(showcloud15), 1, 0)
;



AddLabel(Show_Stats_Label, " range: " + chart_range + (if debug then " (" + use_range + ")" else  "") +" • " + dotcount + " total; " + zonecount + "/" + number_of_zones + " zones" + (if debug then " • big zones: " + Use_Expansive_Zones else "") + (if debug then " • bsd: " + body_standard_deviations + "; vsd: " + volume_standard_deviations else ""), GlobalColor("indicator"));
 
Last edited:
Here's a script that draws boxes as zones instead of lines. It doesn't do what blueantz wants it to do though. Maybe someone here can mash it up with mashume's idea.

# richard_the_red Jimmy Momo Zones

# This study was inspired by Jimmy Momo reactive candles created by @JamesLeFaith. His idea was to draw resistance lines at the open of the largest candles in the range and use those as the basis of supply/demand zones in multiple time periods. This script draws red (short) & green (long) S/D bars and when supply turns demand and back these zones flip colors as price action moves through them.

# Many thanks to @JamesLeFaith for his expertise and collaboration on this project. Without his input, advice,feedback, and in particular his groundbreaking work on reactive candles, this script wouldn't exist. Many people have tried to create a coherent system of supply and demand but I believe his is the first to deliver on that promise.

# This script © richard_the_red. Reactive candles and the Jimmy Momo trading system are the original creation of Jimmy Momo, https://twitter.com/JamesLeFaith.

#This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl.html

# These zones are not a buy or sell indicator or financial advice, and RTR_Jimmy_Momo_Zones is not a financial advisor.




input show_zones = yes; #hint show_zones: Turn the colored zone bars off
input number_of_zones = 10; #hint number_of_zones: Max 15, but more zones mean slower performance
def numzones = Min(number_of_zones, 15);

input Show_Stats_Label = no;

input use_range = {default "Chart Range", "Bars", "Days"}; #hint use_range: Normally zones would be drawn on the biggest candle in the chart range, Bars or Days forces zones to the hard-coded range specified instead.
input range = 0; #hint range: How many bars or days to use if "Chart Range" is not selected. Ignored if 'Use Chart' is selected or the range exceeds the chart range.

input Use_Expansive_Zones = no; #hint Use_Expansive_Zones: Draw zones to the previous candle wick even if that's huge and more zones overlap. Defaults to more precise zones.


#input Only_Show_Below = AggregationPeriod.YEAR;
def isShowing = yes;#GetAggregationPeriod() < Only_Show_Below;
def body_standard_deviations = 1.0; #hint body_standard_deviations: How inclusive candle body calculations are. Smaller is more inclusive, 1.0 is default. Don't change this unless you know what you're doing or at least know how to reset to default.
def body_average_range = 6; #hint body_average_range: The lookback range for average body height
def volume_standard_deviations = 0.2; #hint volume_standard_deviations: How inclusive volume is. Lower is more inclusive. 0.2 is default. If you change this it's on you, man. You probably didn't even read this hint in the first place.
def volume_average_range = 100; #hint volume_average_range: Lookback range to see if volume is above average

def debug = no; #hint debug: Don't.


DefineGlobalColor("indicator", CreateColor(249,233,167));
DefineGlobalColor("long", CreateColor(132,138,63));
DefineGlobalColor("short", CreateColor(189,71,30));

def bn = BarNumber();
def lbn_candidate = If (!IsNaN(close[-1]), bn, lbn_candidate[1]);
def lbn = HighestAll(lbn_candidate);
def chart_scale = GetAggregationPeriod() / 1000 / 60; # minutes

def chart_range;
switch (use_range) {
case "Chart Range":
chart_range = lbn;
case "Bars":
chart_range = range;
case "Days":
chart_range = Min(lbn, range * 16 * (60 / chart_scale));
}
def isInChartRange = bn >= lbn - chart_range;


def l = low;
def h = high;
def v = volume;

def bt = Max(close, open);
def bb = Min(close, open);
def gapDown = If (bb[1] > h, bb[1] - bt, 0);
def gapUp = If (bt[1] < l, bb - bt[1], 0);

def bodytop;
def bodybottom;
def c;
if (gapUp > 0) {
bodytop = bt;
bodybottom = bt[1];
c = bodytop;
} else if (gapDown > 0) {
bodytop = bb[1];
bodybottom = bb;
c = bodybottom;
} else {
bodytop = bt;
bodybottom = bb;
c = close;
}
def o = If (bodytop[1] < c, Min(bodytop[1], open), open); # gappy gap

def body = bodytop - bodybottom;

def isG = c > o;
def isR = c < o;

def body_sd = StDev(body, body_average_range);
def isHotBody = body > body_sd[3] * body_standard_deviations;
def vol_sd = StDev(v, volume_average_range);
def isHotVolume = v > vol_sd[3] * volume_standard_deviations;
def isHot = isHotBody && isHotVolume;
def show = isShowing && isHot;





plot dot = if (show, if (isG, bodybottom, bodytop), Double.NaN);
dot.SetPaintingStrategy(PaintingStrategy.DASHES);
dot.SetLineWeight(2);
dot.AssignValueColor(GlobalColor("indicator"));
dot.HideBubble();
dot.HideTitle();

def wtestc = if (Use_Expansive_Zones, c, l);
def wtesto = if (Use_Expansive_Zones, o, h);
def wick_value = if (show,
if (isG, if (bodytop[1] >= wtestc, l, Min(l[0], l[1])), # green wick is lowest
if (isR, if (bodybottom[1] <= wtesto, h, Max(h[0], h[1])), # red wick is highest
Double.NaN)),
Double.NaN);
plot wick = if (wick_value == dot && !isnan(wick_value), wick_value + .01, wick_value); # need to have something if wick is same as dot.
wick.SetPaintingStrategy(PaintingStrategy.DASHES);
wick.SetLineWeight(1);
wick.AssignValueColor(GlobalColor("indicator"));
wick.HideBubble();
wick.HideTitle();




def g1b = If (body >= g1b[1] && isInChartRange, body, g1b[1]); # set largest bar, all others will be shorter
def g1_bn_candidate = If (body == HighestAll(g1b), bn, Double.NaN);
def g1bn = HighestAll(g1_bn_candidate);
def g1_bn_offset = bn - g1bn;
def g1o = if (g1_bn_offset == 0, dot, GetValue(dot, g1_bn_offset));
def g1w = GetValue(wick, g1_bn_offset);
def showcloud1 = show_zones && numzones >= 1 && g1o && bn >= g1bn;
def g1zt = Max(g1o, g1w);
def g1zb = Min(g1o, g1w);
def g1isLong = bodybottom > g1zt;
def g1isInside = (bodybottom < g1zt && !(bodytop < g1zb) or (bodytop > g1zb && !(bodybottom > g1zt)));
def g1useGreen = If (bn == g1bn, isG, If (g1isInside, g1useGreen[1], g1isLong));
def g1g = g1useGreen;
AddCloud( If (showcloud1, If (g1g, g1zt, g1zb), Double.NaN), If (showcloud1, If (g1g, g1zb, g1zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g1bn && debug, high, "1:" + showcloud1 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g2b = If (body >= g2b[1] && body < HighestAll(g1b) && bn != HighestAll(g1bn) && isInChartRange, body, g2b[1]);
def g2_bn_candidate = If (body == HighestAll(g2b), bn, Double.NaN);
def g2bn = HighestAll(g2_bn_candidate);
def g2_bn_offset = bn - g2bn;
def g2o = GetValue(dot, g2_bn_offset);
def g2w = GetValue(wick, g2_bn_offset);
def showcloud2 = show_zones && numzones >= 2 && g2o && bn >= g2bn;
def g2zt = Max(g2o, g2w);
def g2zb = Min(g2o, g2w);
def g2isLong = bodybottom > g2zt;
def g2isInside = (bodybottom < g2zt && !(bodytop < g2zb) or (bodytop > g2zb && !(bodybottom > g2zt)));
def g2useGreen = If (bn == g2bn, isG, If (g2isInside, g2useGreen[1], g2isLong));
def g2g = g2useGreen;
AddCloud( If (showcloud2, If (g2g, g2zt, g2zb), Double.NaN), If (showcloud2, If (g2g, g2zb, g2zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g2bn && debug, high, "2:" + showcloud2 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g3b = If (body >= g3b[1] && body < HighestAll(g2b) && bn != g2bn && isInChartRange, body, g3b[1]);
def g3_bn_candidate = If (body == HighestAll(g3b), bn, Double.NaN);
def g3bn = HighestAll(g3_bn_candidate);
def g3_bn_offset = bn - g3bn;
def g3o = GetValue(dot, g3_bn_offset);
def g3w = GetValue(wick, g3_bn_offset);
def showcloud3 = show_zones && numzones >= 3 && g3o && bn >= g3bn;
def g3zt = Max(g3o, g3w);
def g3zb = Min(g3o, g3w);
def g3isLong = bodybottom > g3zt;
def g3isInside = (bodybottom < g3zt && !(bodytop < g3zb) or (bodytop > g3zb && !(bodybottom > g3zt)));
def g3useGreen = If (bn == g3bn, isG, If (g3isInside, g3useGreen[1], g3isLong));
def g3g = g3useGreen;
AddCloud( If (showcloud3, If (g3g, g3zt, g3zb), Double.NaN), If (showcloud3, If (g3g, g3zb, g3zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g3bn && debug, high, "3:" + showcloud3 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g4b = If (body >= g4b[1] && body < HighestAll(g3b) && bn != g3bn && isInChartRange, body, g4b[1]);
def g4_bn_candidate = If (body == HighestAll(g4b), bn, Double.NaN);
def g4bn = HighestAll(g4_bn_candidate);
def g4_bn_offset = bn - g4bn;
def g4o = GetValue(dot, g4_bn_offset);
def g4w = GetValue(wick, g4_bn_offset);
def showcloud4 = show_zones && numzones >= 4 && g4o && bn >= g4bn;
def g4zt = Max(g4o, g4w);
def g4zb = Min(g4o, g4w);
def g4isLong = bodybottom > g4zt;
def g4isInside = (bodybottom < g4zt && !(bodytop < g4zb) or (bodytop > g4zb && !(bodybottom > g4zt)));
def g4useGreen = If (bn == g4bn, isG, If (g4isInside, g4useGreen[1], g4isLong));
def g4g = g4useGreen;
AddCloud( If (showcloud4, If (g4g, g4zt, g4zb), Double.NaN), If (showcloud4, If (g4g, g4zb, g4zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g4bn && debug, high, "4:" + showcloud4 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g5b = If (body >= g5b[1] && body < HighestAll(g4b) && bn != g4bn && isInChartRange, body, g5b[1]);
def g5_bn_candidate = If (body == HighestAll(g5b), bn, Double.NaN);
def g5bn = HighestAll(g5_bn_candidate);
def g5_bn_offset = bn - g5bn;
def g5o = GetValue(dot, g5_bn_offset);
def g5w = GetValue(wick, g5_bn_offset);
def showcloud5 = show_zones && numzones >= 5 && g5o && bn >= g5bn;
def g5zt = Max(g5o, g5w);
def g5zb = Min(g5o, g5w);
def g5isLong = bodybottom > g5zt;
def g5isInside = (bodybottom < g5zt && !(bodytop < g5zb) or (bodytop > g5zb && !(bodybottom > g5zt)));
def g5useGreen = If (bn == g5bn, isG, If (g5isInside, g5useGreen[1], g5isLong));
def g5g = g5useGreen;
AddCloud( If (showcloud5, If (g5g, g5zt, g5zb), Double.NaN), If (showcloud5, If (g5g, g5zb, g5zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g5bn && debug, high, "5:" + showcloud5 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g6b = If (body >= g6b[1] && body < HighestAll(g5b) && bn != g5bn && isInChartRange, body, g6b[1]);
def g6_bn_candidate = If (body == HighestAll(g6b), bn, Double.NaN);
def g6bn = HighestAll(g6_bn_candidate);
def g6_bn_offset = bn - g6bn;
def g6o = GetValue(dot, g6_bn_offset);
def g6w = GetValue(wick, g6_bn_offset);
def showcloud6 = show_zones && numzones >= 6 && g6o && bn >= g6bn;
def g6zt = Max(g6o, g6w);
def g6zb = Min(g6o, g6w);
def g6isLong = bodybottom > g6zt;
def g6isInside = (bodybottom < g6zt && !(bodytop < g6zb) or (bodytop > g6zb && !(bodybottom > g6zt)));
def g6useGreen = If (bn == g6bn, isG, If (g6isInside, g6useGreen[1], g6isLong));
def g6g = g6useGreen;
AddCloud( If (showcloud6, If (g6g, g6zt, g6zb), Double.NaN), If (showcloud6, If (g6g, g6zb, g6zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g6bn && debug, high, "6:" + showcloud6 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g7b = If (body >= g7b[1] && body < HighestAll(g6b) && bn != g6bn && isInChartRange, body, g7b[1]);
def g7_bn_candidate = If (body == HighestAll(g7b), bn, Double.NaN);
def g7bn = HighestAll(g7_bn_candidate);
def g7_bn_offset = bn - g7bn;
def g7o = GetValue(dot, g7_bn_offset);
def g7w = GetValue(wick, g7_bn_offset);
def showcloud7 = show_zones && numzones >= 7 && g7o && bn >= g7bn;
def g7zt = Max(g7o, g7w);
def g7zb = Min(g7o, g7w);
def g7isLong = bodybottom > g7zt;
def g7isInside = (bodybottom < g7zt && !(bodytop < g7zb) or (bodytop > g7zb && !(bodybottom > g7zt)));
def g7useGreen = If (bn == g7bn, isG, If (g7isInside, g7useGreen[1], g7isLong));
def g7g = g7useGreen;
AddCloud( If (showcloud7, If (g7g, g7zt, g7zb), Double.NaN), If (showcloud7, If (g7g, g7zb, g7zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g7bn && debug, high, "7:" + showcloud7 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g8b = If (body >= g8b[1] && body < HighestAll(g7b) && bn != g7bn && isInChartRange, body, g8b[1]);
def g8_bn_candidate = If (body == HighestAll(g8b), bn, Double.NaN);
def g8bn = HighestAll(g8_bn_candidate);
def g8_bn_offset = bn - g8bn;
def g8o = GetValue(dot, g8_bn_offset);
def g8w = GetValue(wick, g8_bn_offset);
def showcloud8 = show_zones && numzones >= 8 && g8o && bn >= g8bn;
def g8zt = Max(g8o, g8w);
def g8zb = Min(g8o, g8w);
def g8isLong = bodybottom > g8zt;
def g8isInside = (bodybottom < g8zt && !(bodytop < g8zb) or (bodytop > g8zb && !(bodybottom > g8zt)));
def g8useGreen = If (bn == g8bn, isG, If (g8isInside, g8useGreen[1], g8isLong));
def g8g = g8useGreen;
AddCloud( If (showcloud8, If (g8g, g8zt, g8zb), Double.NaN), If (showcloud8, If (g8g, g8zb, g8zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g8bn && debug, high, "8:" + showcloud8 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g9b = If (body >= g9b[1] && body < HighestAll(g8b) && bn != g8bn && isInChartRange, body, g9b[1]);
def g9_bn_candidate = If (body == HighestAll(g9b), bn, Double.NaN);
def g9bn = HighestAll(g9_bn_candidate);
def g9_bn_offset = bn - g9bn;
def g9o = GetValue(dot, g9_bn_offset);
def g9w = GetValue(wick, g9_bn_offset);
def showcloud9 = show_zones && numzones >= 9 && g9o && bn >= g9bn;
def g9zt = Max(g9o, g9w);
def g9zb = Min(g9o, g9w);
def g9isLong = bodybottom > g9zt;
def g9isInside = (bodybottom < g9zt && !(bodytop < g9zb) or (bodytop > g9zb && !(bodybottom > g9zt)));
def g9useGreen = If (bn == g9bn, isG, If (g9isInside, g9useGreen[1], g9isLong));
def g9g = g9useGreen;
AddCloud( If (showcloud9, If (g9g, g9zt, g9zb), Double.NaN), If (showcloud9, If (g9g, g9zb, g9zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g9bn && debug, high, "9:" + showcloud9 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g10b = If (body >= g10b[1] && body < HighestAll(g9b) && bn != g9bn && isInChartRange, body, g10b[1]);
def g10_bn_candidate = If (body == HighestAll(g10b), bn, Double.NaN);
def g10bn = HighestAll(g10_bn_candidate);
def g10_bn_offset = bn - g10bn;
def g10o = GetValue(dot, g10_bn_offset);
def g10w = GetValue(wick, g10_bn_offset);
def showcloud10 = show_zones && numzones >= 10 && g10o && bn >= g10bn;
def g10zt = Max(g10o, g10w);
def g10zb = Min(g10o, g10w);
def g10isLong = bodybottom > g10zt;
def g10isInside = (bodybottom < g10zt && !(bodytop < g10zb) or (bodytop > g10zb && !(bodybottom > g10zt)));
def g10useGreen = If (bn == g10bn, isG, If (g10isInside, g10useGreen[1], g10isLong));
def g10g = g10useGreen;
AddCloud( If (showcloud10, If (g10g, g10zt, g10zb), Double.NaN), If (showcloud10, If (g10g, g10zb, g10zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g10bn && debug, high, "10:" + showcloud10 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g11b = If (body >= g11b[1] && body < HighestAll(g10b) && bn != g10bn && isInChartRange, body, g11b[1]);
def g11_bn_candidate = If (body == HighestAll(g11b), bn, Double.NaN);
def g11bn = HighestAll(g11_bn_candidate);
def g11_bn_offset = bn - g11bn;
def g11o = GetValue(dot, g11_bn_offset);
def g11w = GetValue(wick, g11_bn_offset);
def showcloud11 = show_zones && numzones >= 11 && g11o && bn >= g11bn;
def g11zt = Max(g11o, g11w);
def g11zb = Min(g11o, g11w);
def g11isLong = bodybottom > g11zt;
def g11isInside = (bodybottom < g11zt && !(bodytop < g11zb) or (bodytop > g11zb && !(bodybottom > g11zt)));
def g11useGreen = If (bn == g11bn, isG, If (g11isInside, g11useGreen[1], g11isLong));
def g11g = g11useGreen;
AddCloud( If (showcloud11, If (g11g, g11zt, g11zb), Double.NaN), If (showcloud11, If (g11g, g11zb, g11zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g11bn && debug, high, "11:" + showcloud11 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g12b = If (body >= g12b[1] && body < HighestAll(g11b) && bn != g11bn && isInChartRange, body, g12b[1]);
def g12_bn_candidate = If (body == HighestAll(g12b), bn, Double.NaN);
def g12bn = HighestAll(g12_bn_candidate);
def g12_bn_offset = bn - g12bn;
def g12o = GetValue(dot, g12_bn_offset);
def g12w = GetValue(wick, g12_bn_offset);
def showcloud12 = show_zones && numzones >= 12 && g12o && bn >= g12bn;
def g12zt = Max(g12o, g12w);
def g12zb = Min(g12o, g12w);
def g12isLong = bodybottom > g12zt;
def g12isInside = (bodybottom < g12zt && !(bodytop < g12zb) or (bodytop > g12zb && !(bodybottom > g12zt)));
def g12useGreen = If (bn == g12bn, isG, If (g12isInside, g12useGreen[1], g12isLong));
def g12g = g12useGreen;
AddCloud( If (showcloud12, If (g12g, g12zt, g12zb), Double.NaN), If (showcloud12, If (g12g, g12zb, g12zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g12bn && debug, high, "12:" + showcloud12 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g13b = If (body >= g13b[1] && body < HighestAll(g12b) && bn != g12bn && isInChartRange, body, g13b[1]);
def g13_bn_candidate = If (body == HighestAll(g13b), bn, Double.NaN);
def g13bn = HighestAll(g13_bn_candidate);
def g13_bn_offset = bn - g13bn;
def g13o = GetValue(dot, g13_bn_offset);
def g13w = GetValue(wick, g13_bn_offset);
def showcloud13 = show_zones && numzones >= 13 && g13o && bn >= g13bn;
def g13zt = Max(g13o, g13w);
def g13zb = Min(g13o, g13w);
def g13isLong = bodybottom > g13zt;
def g13isInside = (bodybottom < g13zt && !(bodytop < g13zb) or (bodytop > g13zb && !(bodybottom > g13zt)));
def g13useGreen = If (bn == g13bn, isG, If (g13isInside, g13useGreen[1], g13isLong));
def g13g = g13useGreen;
AddCloud( If (showcloud13, If (g13g, g13zt, g13zb), Double.NaN), If (showcloud13, If (g13g, g13zb, g13zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g13bn && debug, high, "13:" + showcloud13 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g14b = If (body >= g14b[1] && body < HighestAll(g13b) && bn != g13bn && isInChartRange, body, g14b[1]);
def g14_bn_candidate = If (body == HighestAll(g14b), bn, Double.NaN);
def g14bn = HighestAll(g14_bn_candidate);
def g14_bn_offset = bn - g14bn;
def g14o = GetValue(dot, g14_bn_offset);
def g14w = GetValue(wick, g14_bn_offset);
def showcloud14 = show_zones && numzones >= 14 && g14o && bn >= g14bn;
def g14zt = Max(g14o, g14w);
def g14zb = Min(g14o, g14w);
def g14isLong = bodybottom > g14zt;
def g14isInside = (bodybottom < g14zt && !(bodytop < g14zb) or (bodytop > g14zb && !(bodybottom > g14zt)));
def g14useGreen = If (bn == g14bn, isG, If (g14isInside, g14useGreen[1], g14isLong));
def g14g = g14useGreen;
AddCloud( If (showcloud14, If (g14g, g14zt, g14zb), Double.NaN), If (showcloud14, If (g14g, g14zb, g14zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g14bn && debug, high, "14:" + showcloud14 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g15b = If (body >= g15b[1] && body < HighestAll(g14b) && bn != g14bn && isInChartRange, body, g15b[1]);
def g15_bn_candidate = If (body == HighestAll(g15b), bn, Double.NaN);
def g15bn = HighestAll(g15_bn_candidate);
def g15_bn_offset = bn - g15bn;
def g15o = GetValue(dot, g15_bn_offset);
def g15w = GetValue(wick, g15_bn_offset);
def showcloud15 = show_zones && numzones >= 15 && g15o && bn >= g15bn;
def g15zt = Max(g15o, g15w);
def g15zb = Min(g15o, g15w);
def g15isLong = bodybottom > g15zt;
def g15isInside = (bodybottom < g15zt && !(bodytop < g15zb) or (bodytop > g15zb && !(bodybottom > g15zt)));
def g15useGreen = If (bn == g15bn, isG, If (g15isInside, g15useGreen[1], g15isLong));
def g15g = g15useGreen;
AddCloud( If (showcloud15, If (g15g, g15zt, g15zb), Double.NaN), If (showcloud15, If (g15g, g15zb, g15zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g15bn && debug, high, "15:" + showcloud15 + "; dot: " + dot + "; wick: " + wick, color.white, yes);


def dotcount = dotcount[1] + If (isHot, 1, 0);
def zonecount =
If (!IsNaN(showcloud1), 1, 0)
  • If (!IsNaN(showcloud2), 1, 0)
  • If (!IsNaN(showcloud3), 1, 0)
  • If (!IsNaN(showcloud4), 1, 0)
  • If (!IsNaN(showcloud5), 1, 0)
  • If (!IsNaN(showcloud6), 1, 0)
  • If (!IsNaN(showcloud7), 1, 0)
  • If (!IsNaN(showcloud8), 1, 0)
  • If (!IsNaN(showcloud9), 1, 0)
  • If (!IsNaN(showcloud10), 1, 0)
  • If (!IsNaN(showcloud11), 1, 0)
  • If (!IsNaN(showcloud12), 1, 0)
  • If (!IsNaN(showcloud13), 1, 0)
  • If (!IsNaN(showcloud14), 1, 0)
  • If (!IsNaN(showcloud15), 1, 0)
;



AddLabel(Show_Stats_Label, " range: " + chart_range + (if debug then " (" + use_range + ")" else "") +" • " + dotcount + " total; " + zonecount + "/" + number_of_zones + " zones" + (if debug then " • big zones: " + Use_Expansive_Zones else "") + (if debug then " • bsd: " + body_standard_deviations + "; vsd: " + volume_standard_deviations else ""), GlobalColor("indicator"));


when posting codes, please post in a code window.
in the header, click on <\>

please edit your post 3,
delete all the code, then copy the original code and paste it into a code window. don't just copy what is in post3, it is already altered.


near the end, this formula doesn't look right. it has bullet points added.
i think maybe it should have a bunch of * ??
the point is, without posting in a code window, some character combinations get changed into other characters.

def zonecount =
If (!IsNaN(showcloud1), 1, 0)
If (!IsNaN(showcloud2), 1, 0)
If (!IsNaN(showcloud3), 1, 0)
 
Here's a script that draws boxes as zones instead of lines. It doesn't do what blueantz wants it to do though. Maybe someone here can mash it up with mashume's idea.

Code:
# richard_the_red Jimmy Momo Zones

# This study was inspired by Jimmy Momo reactive candles created by @JamesLeFaith. His idea was to draw resistance lines at the open of the largest candles in the range and use those as the basis of supply/demand zones in multiple time periods. This script draws red (short) & green (long) S/D bars and when supply turns demand and back these zones flip colors as price action moves through them.

# Many thanks to @JamesLeFaith for his expertise and collaboration on this project. Without his input, advice,feedback, and in particular his groundbreaking work on reactive candles, this script wouldn't exist. Many people have tried to create a coherent system of supply and demand but I believe his is the first to deliver on that promise.

# This script © richard_the_red. Reactive candles and the Jimmy Momo trading system are the original creation of Jimmy Momo, [URL]https://twitter.com/JamesLeFaith[/URL].

#This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. [URL]http://www.gnu.org/licenses/gpl.html[/URL]

# These zones are not a buy or sell indicator or financial advice, and RTR_Jimmy_Momo_Zones is not a financial advisor.




input show_zones = yes;  #hint show_zones: Turn the colored zone bars off
input number_of_zones = 10; #hint number_of_zones: Max 15, but more zones mean slower performance
def numzones = Min(number_of_zones, 15);

input Show_Stats_Label = no;

input use_range = {default "Chart Range", "Bars", "Days"}; #hint use_range: Normally zones would be drawn on the biggest candle in the chart range, Bars or Days forces zones to the hard-coded range specified instead.
input range = 0; #hint range: How many bars or days to use if "Chart Range" is not selected. Ignored if 'Use Chart' is selected or the range exceeds the chart range.

input Use_Expansive_Zones = no; #hint Use_Expansive_Zones: Draw zones to the previous candle wick even if that's huge and more zones overlap. Defaults to more precise zones.


#input Only_Show_Below = AggregationPeriod.YEAR;
def isShowing = yes;#GetAggregationPeriod() < Only_Show_Below;
def body_standard_deviations = 1.0; #hint body_standard_deviations: How inclusive candle body calculations are. Smaller is more inclusive, 1.0 is default. Don't change this unless you know what you're doing or at least know how to reset to default.
def body_average_range = 6; #hint body_average_range: The lookback range for average body height
def volume_standard_deviations = 0.2; #hint volume_standard_deviations: How inclusive volume is. Lower is more inclusive. 0.2 is default. If you change this it's on you, man. You probably didn't even read this hint in the first place.
def volume_average_range = 100; #hint volume_average_range: Lookback range to see if volume is above average

def debug = no; #hint debug: Don't.


DefineGlobalColor("indicator", CreateColor(249,233,167));
DefineGlobalColor("long", CreateColor(132,138,63));
DefineGlobalColor("short", CreateColor(189,71,30));

def bn = BarNumber();
def lbn_candidate = If (!IsNaN(close[-1]), bn, lbn_candidate[1]);
def lbn = HighestAll(lbn_candidate);
def chart_scale = GetAggregationPeriod() / 1000 / 60; # minutes

def chart_range;
switch (use_range) {
case "Chart Range":
    chart_range = lbn;
case "Bars":
    chart_range = range;
case "Days":
    chart_range = Min(lbn, range * 16 * (60 / chart_scale));
}
def isInChartRange = bn >= lbn - chart_range;


def l = low;
def h = high;
def v = volume;

def bt = Max(close, open);
def bb = Min(close, open);
def gapDown = If (bb[1] > h, bb[1] - bt, 0);
def gapUp = If (bt[1] < l, bb - bt[1], 0);

def bodytop;
def bodybottom;
def c;
if (gapUp > 0) {
    bodytop = bt;
    bodybottom = bt[1];
    c = bodytop;
} else if (gapDown > 0) {
    bodytop = bb[1];
    bodybottom = bb;
    c = bodybottom;
} else {
    bodytop = bt;
    bodybottom = bb;
    c = close;
}
def o = If (bodytop[1] < c, Min(bodytop[1], open), open); # gappy gap

def body = bodytop - bodybottom;

def isG = c > o;
def isR = c < o;

def body_sd = StDev(body, body_average_range);
def isHotBody = body > body_sd[3] * body_standard_deviations;
def vol_sd = StDev(v, volume_average_range);
def isHotVolume = v > vol_sd[3] * volume_standard_deviations;
def isHot = isHotBody && isHotVolume;
def show = isShowing && isHot;





plot dot = if (show, if (isG, bodybottom, bodytop), Double.NaN);
dot.SetPaintingStrategy(PaintingStrategy.DASHES);
dot.SetLineWeight(2);
dot.AssignValueColor(GlobalColor("indicator"));
dot.HideBubble();
dot.HideTitle();

def wtestc = if (Use_Expansive_Zones, c, l);
def wtesto = if (Use_Expansive_Zones, o, h);
def wick_value = if (show,
    if (isG, if (bodytop[1] >= wtestc, l, Min(l[0], l[1])), # green wick is lowest
    if (isR, if (bodybottom[1] <= wtesto, h, Max(h[0], h[1])), # red wick is highest
    Double.NaN)),
Double.NaN);
plot wick = if (wick_value == dot && !isnan(wick_value), wick_value + .01, wick_value); # need to have something if wick is same as dot.
wick.SetPaintingStrategy(PaintingStrategy.DASHES);
wick.SetLineWeight(1);
wick.AssignValueColor(GlobalColor("indicator"));
wick.HideBubble();
wick.HideTitle();




def g1b = If (body >= g1b[1] && isInChartRange, body, g1b[1]); # set largest bar, all others will be shorter
def g1_bn_candidate = If (body == HighestAll(g1b), bn, Double.NaN);
def g1bn = HighestAll(g1_bn_candidate);
def g1_bn_offset = bn - g1bn;
def g1o = if (g1_bn_offset == 0, dot, GetValue(dot, g1_bn_offset));
def g1w = GetValue(wick, g1_bn_offset);
def showcloud1 = show_zones && numzones >= 1 && g1o && bn >= g1bn;
def g1zt = Max(g1o, g1w);
def g1zb = Min(g1o, g1w);
def g1isLong = bodybottom > g1zt;
def g1isInside = (bodybottom < g1zt && !(bodytop < g1zb) or (bodytop > g1zb && !(bodybottom > g1zt)));
def g1useGreen = If (bn == g1bn, isG, If (g1isInside, g1useGreen[1], g1isLong));
def g1g = g1useGreen;
AddCloud( If (showcloud1, If (g1g, g1zt, g1zb), Double.NaN), If (showcloud1, If (g1g, g1zb, g1zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g1bn && debug, high, "1:" + showcloud1 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g2b = If (body >= g2b[1] && body < HighestAll(g1b) && bn != HighestAll(g1bn) && isInChartRange, body, g2b[1]);
def g2_bn_candidate = If (body == HighestAll(g2b), bn, Double.NaN);
def g2bn = HighestAll(g2_bn_candidate);
def g2_bn_offset = bn - g2bn;
def g2o = GetValue(dot, g2_bn_offset);
def g2w = GetValue(wick, g2_bn_offset);
def showcloud2 = show_zones && numzones >= 2 && g2o && bn >= g2bn;
def g2zt = Max(g2o, g2w);
def g2zb = Min(g2o, g2w);
def g2isLong = bodybottom > g2zt;
def g2isInside = (bodybottom < g2zt && !(bodytop < g2zb) or (bodytop > g2zb && !(bodybottom > g2zt)));
def g2useGreen = If (bn == g2bn, isG, If (g2isInside, g2useGreen[1], g2isLong));
def g2g = g2useGreen;
AddCloud( If (showcloud2, If (g2g, g2zt, g2zb), Double.NaN), If (showcloud2, If (g2g, g2zb, g2zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g2bn && debug, high, "2:" + showcloud2 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g3b = If (body >= g3b[1] && body < HighestAll(g2b) && bn != g2bn && isInChartRange, body, g3b[1]);
def g3_bn_candidate = If (body == HighestAll(g3b), bn, Double.NaN);
def g3bn = HighestAll(g3_bn_candidate);
def g3_bn_offset = bn - g3bn;
def g3o = GetValue(dot, g3_bn_offset);
def g3w = GetValue(wick, g3_bn_offset);
def showcloud3 = show_zones && numzones >= 3 && g3o && bn >= g3bn;
def g3zt = Max(g3o, g3w);
def g3zb = Min(g3o, g3w);
def g3isLong = bodybottom > g3zt;
def g3isInside = (bodybottom < g3zt && !(bodytop < g3zb) or (bodytop > g3zb && !(bodybottom > g3zt)));
def g3useGreen = If (bn == g3bn, isG, If (g3isInside, g3useGreen[1], g3isLong));
def g3g = g3useGreen;
AddCloud( If (showcloud3, If (g3g, g3zt, g3zb), Double.NaN), If (showcloud3, If (g3g, g3zb, g3zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g3bn && debug, high, "3:" + showcloud3 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g4b = If (body >= g4b[1] && body < HighestAll(g3b) && bn != g3bn && isInChartRange, body, g4b[1]);
def g4_bn_candidate = If (body == HighestAll(g4b), bn, Double.NaN);
def g4bn = HighestAll(g4_bn_candidate);
def g4_bn_offset = bn - g4bn;
def g4o = GetValue(dot, g4_bn_offset);
def g4w = GetValue(wick, g4_bn_offset);
def showcloud4 = show_zones && numzones >= 4 && g4o && bn >= g4bn;
def g4zt = Max(g4o, g4w);
def g4zb = Min(g4o, g4w);
def g4isLong = bodybottom > g4zt;
def g4isInside = (bodybottom < g4zt && !(bodytop < g4zb) or (bodytop > g4zb && !(bodybottom > g4zt)));
def g4useGreen = If (bn == g4bn, isG, If (g4isInside, g4useGreen[1], g4isLong));
def g4g = g4useGreen;
AddCloud( If (showcloud4, If (g4g, g4zt, g4zb), Double.NaN), If (showcloud4, If (g4g, g4zb, g4zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g4bn && debug, high, "4:" + showcloud4 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g5b = If (body >= g5b[1] && body < HighestAll(g4b) && bn != g4bn && isInChartRange, body, g5b[1]);
def g5_bn_candidate = If (body == HighestAll(g5b), bn, Double.NaN);
def g5bn = HighestAll(g5_bn_candidate);
def g5_bn_offset = bn - g5bn;
def g5o = GetValue(dot, g5_bn_offset);
def g5w = GetValue(wick, g5_bn_offset);
def showcloud5 = show_zones && numzones >= 5 && g5o && bn >= g5bn;
def g5zt = Max(g5o, g5w);
def g5zb = Min(g5o, g5w);
def g5isLong = bodybottom > g5zt;
def g5isInside = (bodybottom < g5zt && !(bodytop < g5zb) or (bodytop > g5zb && !(bodybottom > g5zt)));
def g5useGreen = If (bn == g5bn, isG, If (g5isInside, g5useGreen[1], g5isLong));
def g5g = g5useGreen;
AddCloud( If (showcloud5, If (g5g, g5zt, g5zb), Double.NaN), If (showcloud5, If (g5g, g5zb, g5zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g5bn && debug, high, "5:" + showcloud5 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g6b = If (body >= g6b[1] && body < HighestAll(g5b) && bn != g5bn && isInChartRange, body, g6b[1]);
def g6_bn_candidate = If (body == HighestAll(g6b), bn, Double.NaN);
def g6bn = HighestAll(g6_bn_candidate);
def g6_bn_offset = bn - g6bn;
def g6o = GetValue(dot, g6_bn_offset);
def g6w = GetValue(wick, g6_bn_offset);
def showcloud6 = show_zones && numzones >= 6 && g6o && bn >= g6bn;
def g6zt = Max(g6o, g6w);
def g6zb = Min(g6o, g6w);
def g6isLong = bodybottom > g6zt;
def g6isInside = (bodybottom < g6zt && !(bodytop < g6zb) or (bodytop > g6zb && !(bodybottom > g6zt)));
def g6useGreen = If (bn == g6bn, isG, If (g6isInside, g6useGreen[1], g6isLong));
def g6g = g6useGreen;
AddCloud( If (showcloud6, If (g6g, g6zt, g6zb), Double.NaN), If (showcloud6, If (g6g, g6zb, g6zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g6bn && debug, high, "6:" + showcloud6 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g7b = If (body >= g7b[1] && body < HighestAll(g6b) && bn != g6bn && isInChartRange, body, g7b[1]);
def g7_bn_candidate = If (body == HighestAll(g7b), bn, Double.NaN);
def g7bn = HighestAll(g7_bn_candidate);
def g7_bn_offset = bn - g7bn;
def g7o = GetValue(dot, g7_bn_offset);
def g7w = GetValue(wick, g7_bn_offset);
def showcloud7 = show_zones && numzones >= 7 && g7o && bn >= g7bn;
def g7zt = Max(g7o, g7w);
def g7zb = Min(g7o, g7w);
def g7isLong = bodybottom > g7zt;
def g7isInside = (bodybottom < g7zt && !(bodytop < g7zb) or (bodytop > g7zb && !(bodybottom > g7zt)));
def g7useGreen = If (bn == g7bn, isG, If (g7isInside, g7useGreen[1], g7isLong));
def g7g = g7useGreen;
AddCloud( If (showcloud7, If (g7g, g7zt, g7zb), Double.NaN), If (showcloud7, If (g7g, g7zb, g7zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g7bn && debug, high, "7:" + showcloud7 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g8b = If (body >= g8b[1] && body < HighestAll(g7b) && bn != g7bn && isInChartRange, body, g8b[1]);
def g8_bn_candidate = If (body == HighestAll(g8b), bn, Double.NaN);
def g8bn = HighestAll(g8_bn_candidate);
def g8_bn_offset = bn - g8bn;
def g8o = GetValue(dot, g8_bn_offset);
def g8w = GetValue(wick, g8_bn_offset);
def showcloud8 = show_zones && numzones >= 8 && g8o && bn >= g8bn;
def g8zt = Max(g8o, g8w);
def g8zb = Min(g8o, g8w);
def g8isLong = bodybottom > g8zt;
def g8isInside = (bodybottom < g8zt && !(bodytop < g8zb) or (bodytop > g8zb && !(bodybottom > g8zt)));
def g8useGreen = If (bn == g8bn, isG, If (g8isInside, g8useGreen[1], g8isLong));
def g8g = g8useGreen;
AddCloud( If (showcloud8, If (g8g, g8zt, g8zb), Double.NaN), If (showcloud8, If (g8g, g8zb, g8zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g8bn && debug, high, "8:" + showcloud8 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g9b = If (body >= g9b[1] && body < HighestAll(g8b) && bn != g8bn && isInChartRange, body, g9b[1]);
def g9_bn_candidate = If (body == HighestAll(g9b), bn, Double.NaN);
def g9bn = HighestAll(g9_bn_candidate);
def g9_bn_offset = bn - g9bn;
def g9o = GetValue(dot, g9_bn_offset);
def g9w = GetValue(wick, g9_bn_offset);
def showcloud9 = show_zones && numzones >= 9 && g9o && bn >= g9bn;
def g9zt = Max(g9o, g9w);
def g9zb = Min(g9o, g9w);
def g9isLong = bodybottom > g9zt;
def g9isInside = (bodybottom < g9zt && !(bodytop < g9zb) or (bodytop > g9zb && !(bodybottom > g9zt)));
def g9useGreen = If (bn == g9bn, isG, If (g9isInside, g9useGreen[1], g9isLong));
def g9g = g9useGreen;
AddCloud( If (showcloud9, If (g9g, g9zt, g9zb), Double.NaN), If (showcloud9, If (g9g, g9zb, g9zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g9bn && debug, high, "9:" + showcloud9 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g10b = If (body >= g10b[1] && body < HighestAll(g9b) && bn != g9bn && isInChartRange, body, g10b[1]);
def g10_bn_candidate = If (body == HighestAll(g10b), bn, Double.NaN);
def g10bn = HighestAll(g10_bn_candidate);
def g10_bn_offset = bn - g10bn;
def g10o = GetValue(dot, g10_bn_offset);
def g10w = GetValue(wick, g10_bn_offset);
def showcloud10 = show_zones && numzones >= 10 && g10o && bn >= g10bn;
def g10zt = Max(g10o, g10w);
def g10zb = Min(g10o, g10w);
def g10isLong = bodybottom > g10zt;
def g10isInside = (bodybottom < g10zt && !(bodytop < g10zb) or (bodytop > g10zb && !(bodybottom > g10zt)));
def g10useGreen = If (bn == g10bn, isG, If (g10isInside, g10useGreen[1], g10isLong));
def g10g = g10useGreen;
AddCloud( If (showcloud10, If (g10g, g10zt, g10zb), Double.NaN), If (showcloud10, If (g10g, g10zb, g10zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g10bn && debug, high, "10:" + showcloud10 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g11b = If (body >= g11b[1] && body < HighestAll(g10b) && bn != g10bn && isInChartRange, body, g11b[1]);
def g11_bn_candidate = If (body == HighestAll(g11b), bn, Double.NaN);
def g11bn = HighestAll(g11_bn_candidate);
def g11_bn_offset = bn - g11bn;
def g11o = GetValue(dot, g11_bn_offset);
def g11w = GetValue(wick, g11_bn_offset);
def showcloud11 = show_zones && numzones >= 11 && g11o && bn >= g11bn;
def g11zt = Max(g11o, g11w);
def g11zb = Min(g11o, g11w);
def g11isLong = bodybottom > g11zt;
def g11isInside = (bodybottom < g11zt && !(bodytop < g11zb) or (bodytop > g11zb && !(bodybottom > g11zt)));
def g11useGreen = If (bn == g11bn, isG, If (g11isInside, g11useGreen[1], g11isLong));
def g11g = g11useGreen;
AddCloud( If (showcloud11, If (g11g, g11zt, g11zb), Double.NaN), If (showcloud11, If (g11g, g11zb, g11zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g11bn && debug, high, "11:" + showcloud11 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g12b = If (body >= g12b[1] && body < HighestAll(g11b) && bn != g11bn && isInChartRange, body, g12b[1]);
def g12_bn_candidate = If (body == HighestAll(g12b), bn, Double.NaN);
def g12bn = HighestAll(g12_bn_candidate);
def g12_bn_offset = bn - g12bn;
def g12o = GetValue(dot, g12_bn_offset);
def g12w = GetValue(wick, g12_bn_offset);
def showcloud12 = show_zones && numzones >= 12 && g12o && bn >= g12bn;
def g12zt = Max(g12o, g12w);
def g12zb = Min(g12o, g12w);
def g12isLong = bodybottom > g12zt;
def g12isInside = (bodybottom < g12zt && !(bodytop < g12zb) or (bodytop > g12zb && !(bodybottom > g12zt)));
def g12useGreen = If (bn == g12bn, isG, If (g12isInside, g12useGreen[1], g12isLong));
def g12g = g12useGreen;
AddCloud( If (showcloud12, If (g12g, g12zt, g12zb), Double.NaN), If (showcloud12, If (g12g, g12zb, g12zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g12bn && debug, high, "12:" + showcloud12 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g13b = If (body >= g13b[1] && body < HighestAll(g12b) && bn != g12bn && isInChartRange, body, g13b[1]);
def g13_bn_candidate = If (body == HighestAll(g13b), bn, Double.NaN);
def g13bn = HighestAll(g13_bn_candidate);
def g13_bn_offset = bn - g13bn;
def g13o = GetValue(dot, g13_bn_offset);
def g13w = GetValue(wick, g13_bn_offset);
def showcloud13 = show_zones && numzones >= 13 && g13o && bn >= g13bn;
def g13zt = Max(g13o, g13w);
def g13zb = Min(g13o, g13w);
def g13isLong = bodybottom > g13zt;
def g13isInside = (bodybottom < g13zt && !(bodytop < g13zb) or (bodytop > g13zb && !(bodybottom > g13zt)));
def g13useGreen = If (bn == g13bn, isG, If (g13isInside, g13useGreen[1], g13isLong));
def g13g = g13useGreen;
AddCloud( If (showcloud13, If (g13g, g13zt, g13zb), Double.NaN), If (showcloud13, If (g13g, g13zb, g13zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g13bn && debug, high, "13:" + showcloud13 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g14b = If (body >= g14b[1] && body < HighestAll(g13b) && bn != g13bn && isInChartRange, body, g14b[1]);
def g14_bn_candidate = If (body == HighestAll(g14b), bn, Double.NaN);
def g14bn = HighestAll(g14_bn_candidate);
def g14_bn_offset = bn - g14bn;
def g14o = GetValue(dot, g14_bn_offset);
def g14w = GetValue(wick, g14_bn_offset);
def showcloud14 = show_zones && numzones >= 14 && g14o && bn >= g14bn;
def g14zt = Max(g14o, g14w);
def g14zb = Min(g14o, g14w);
def g14isLong = bodybottom > g14zt;
def g14isInside = (bodybottom < g14zt && !(bodytop < g14zb) or (bodytop > g14zb && !(bodybottom > g14zt)));
def g14useGreen = If (bn == g14bn, isG, If (g14isInside, g14useGreen[1], g14isLong));
def g14g = g14useGreen;
AddCloud( If (showcloud14, If (g14g, g14zt, g14zb), Double.NaN), If (showcloud14, If (g14g, g14zb, g14zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g14bn && debug, high, "14:" + showcloud14 + "; dot: " + dot + "; wick: " + wick, color.white, yes);

def g15b = If (body >= g15b[1] && body < HighestAll(g14b) && bn != g14bn && isInChartRange, body, g15b[1]);
def g15_bn_candidate = If (body == HighestAll(g15b), bn, Double.NaN);
def g15bn = HighestAll(g15_bn_candidate);
def g15_bn_offset = bn - g15bn;
def g15o = GetValue(dot, g15_bn_offset);
def g15w = GetValue(wick, g15_bn_offset);
def showcloud15 = show_zones && numzones >= 15 && g15o && bn >= g15bn;
def g15zt = Max(g15o, g15w);
def g15zb = Min(g15o, g15w);
def g15isLong = bodybottom > g15zt;
def g15isInside = (bodybottom < g15zt && !(bodytop < g15zb) or (bodytop > g15zb && !(bodybottom > g15zt)));
def g15useGreen = If (bn == g15bn, isG, If (g15isInside, g15useGreen[1], g15isLong));
def g15g = g15useGreen;
AddCloud( If (showcloud15, If (g15g, g15zt, g15zb), Double.NaN), If (showcloud15, If (g15g, g15zb, g15zt), Double.NaN), GlobalColor("long"), GlobalColor("short"), no);
addchartbubble(bn == g15bn && debug, high, "15:" + showcloud15 + "; dot: " + dot + "; wick: " + wick, color.white, yes);


def dotcount = dotcount[1] + If (isHot, 1, 0);
def zonecount =
  If (!IsNaN(showcloud1), 1, 0)
[LIST]
[*]If (!IsNaN(showcloud2), 1, 0)
[*]If (!IsNaN(showcloud3), 1, 0)
[*]If (!IsNaN(showcloud4), 1, 0)
[*]If (!IsNaN(showcloud5), 1, 0)
[*]If (!IsNaN(showcloud6), 1, 0)
[*]If (!IsNaN(showcloud7), 1, 0)
[*]If (!IsNaN(showcloud8), 1, 0)
[*]If (!IsNaN(showcloud9), 1, 0)
[*]If (!IsNaN(showcloud10), 1, 0)
[*]If (!IsNaN(showcloud11), 1, 0)
[*]If (!IsNaN(showcloud12), 1, 0)
[*]If (!IsNaN(showcloud13), 1, 0)
[*]If (!IsNaN(showcloud14), 1, 0)
[*]If (!IsNaN(showcloud15), 1, 0)
[/LIST]
;



AddLabel(Show_Stats_Label, " range: " + chart_range + (if debug then " (" + use_range + ")" else  "") +" • " + dotcount + " total; " + zonecount + "/" + number_of_zones + " zones" + (if debug then " • big zones: " + Use_Expansive_Zones else "") + (if debug then " • bsd: " + body_standard_deviations + "; vsd: " + volume_standard_deviations else ""), GlobalColor("indicator"));
yeah id be curious to check this out in the correct format, looks like the bottom has errors. Thanks!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
484 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top