Inside and Up/Down box

conmayne

Member
VIP
def insideBar = close < close[1] and close > open[1] or close < open[1] and close > close[1];
def InsideUp = insideBar[1] and close > high[1] ;
def InsideDown = insideBar[1] and close < low[1] ;

I'm trying to get TOS to plot a green box over any inside and ups that extends all the way to the right. vice versa for the inside and downs with a red highlighted box. Can anyone help me with that real quick? I want it to look like mobius pivot lines indicator boxes.
 
Solution
i am not sure of your inside bar formula. ( maybe it's too late)
i left it in , but disabled it, so you could re-enable it if you want to.
i added my own inside bar formula.

patched code from post#2

i loaded my code from post2 and noticed sometimes there were lines at 0 during the first few bars.
i added a check , if barnumber 1 then na


Code:
# inside_updown_box_mod01b

# https://usethinkscript.com/threads/inside-and-up-down-box.11130/
# Inside and Up/Down box


input candle_levels = {default "wick" , "body" };
input show_big_bar_level_lines = yes;

def bn = barnumber();
def na = double.nan;

# choose price levels for inside bar , wicks or body
def highx;
def lowx;
def t;
switch (candle_levels) {
case "wick":
  highx = high...
def insideBar = close < close[1] and close > open[1] or close < open[1] and close > close[1];
def InsideUp = insideBar[1] and close > high[1] ;
def InsideDown = insideBar[1] and close < low[1] ;

I'm trying to get TOS to plot a green box over any inside and ups that extends all the way to the right. vice versa for the inside and downs with a red highlighted box. Can anyone help me with that real quick? I want it to look like mobius pivot lines indicator boxes.

i am not sure of your inside bar formula. ( maybe it's too late)
i left it in , but disabled it, so you could re-enable it if you want to.
i added my own inside bar formula.

i'm not familiar with mobius pivot boxes. if you want a study to influence a new study, post the code and a picture of it.

----------------------------------

there will probably be many, dozens , of inside bars on a chart.
to have lines extending from all of them, would require a unique set of supporting formulas and a separate plot formula for each one. not practical. this version plots lines from an up inside bar, until the next up bar. same for down inside bars.

take a look at this gap study, to give you an idea of having more than 1 line plotted on a bar. it can plot 4 sets of lines at a time.
https://usethinkscript.com/threads/...ses-into-it-for-thinkorswim.11186/#post-97764

---------------------------------

draw horizontal lines, from an inside bar,
when the next bar is higher or lower than the inside bar.

can choose price levels for inside bar, wicks or body.

can draw lines from the mother bar, the bigger one before the inside bar, for a few bars.


Ruby:
# inside_updown_box_0

input candle_levels = {default "wick" , "body" };
input show_big_bar_level_lines = yes;

def na = double.nan;

# choose price levels for inside bar , wicks or body
def highx;
def lowx;
def t;
switch (candle_levels) {
case "wick":
  highx = high;
  lowx = low;
  t = 1;
case "body":
  highx = Max( open, close);
  lowx = Min( open, close);
  t = 2;
}

addlabel(1, "Inside bar based on " + (if t == 1 then "Wick levels" else "Body levels"), color.yellow);


# ?? original code ,  body inside bar ?
#def insideBar = close < close[1] and close > open[1] or close < open[1] and close > close[1];

# 'normal' inside bar formula , wicks
#def insideBar = low[1] < low and high[1] > high;

def insideBar = lowx[1] < lowx and highx[1] > highx;

def InsideUp = insideBar[1] and close > highx[1] ;
def InsideDown = insideBar[1] and close < lowx[1] ;

def uphi = if InsideUp then highx[1] else if InsideUp[-1] then na else uphi[1];
def uplo = if InsideUp then lowx[1] else if InsideUp[-1] then na else uplo[1];
def dwnhi = if Insidedown then highx[1] else if Insidedown[-1] then na else dwnhi[1];
def dwnlo = if Insidedown then lowx[1] else if Insidedown[-1] then na else dwnlo[1];

plot zuphi = uphi; 
zuphi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zuphi.SetDefaultColor(Color.light_green);
zuphi.hidebubble();

plot zuplo = uplo;
zuplo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zuplo.SetDefaultColor(Color.light_green);
zuplo.hidebubble();

plot zdwnhi = dwnhi;
zdwnhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwnhi.SetDefaultColor(Color.light_red);
zdwnhi.hidebubble();

plot zdwnlo = dwnlo;
zdwnlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwnlo.SetDefaultColor(Color.light_red);
zdwnlo.hidebubble();

addcloud(zuphi, zuplo, color.green, color.light_green);
addcloud(zdwnhi, zdwnlo, color.red, color.light_red);


# -------------------------
# show lines from mother bar ,big bar

def x = 4;
def biguphi = if InsideUp[-2] then highx[0] else if InsideUp[x] then na else biguphi[1];
def biguplo = if InsideUp[-2] then lowx[0] else if InsideUp[x] then na else biguplo[1];
def bigdwnhi = if Insidedown[-2] then highx[0] else if Insidedown[x] then na else bigdwnhi[1];
def bigdwnlo = if Insidedown[-2] then lowx[0] else if Insidedown[x] then na else bigdwnlo[1];

plot z1 = biguphi;
plot z2 = biguplo;
plot z3 = bigdwnhi;
plot z4 = bigdwnlo;

z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1.SetDefaultColor(Color.lime);
z1.hidebubble();
z1.SetHiding(!show_big_bar_level_lines);
z1.SetStyle(Curve.MEDIUM_DASH);

z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetDefaultColor(Color.lime);
z2.hidebubble();
z2.SetHiding(!show_big_bar_level_lines);
z2.SetStyle(Curve.MEDIUM_DASH);

z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3.SetDefaultColor(Color.magenta);
z3.hidebubble();
z3.SetHiding(!show_big_bar_level_lines);
z3.SetStyle(Curve.MEDIUM_DASH);

z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetDefaultColor(Color.magenta);
z4.hidebubble();
z4.SetHiding(!show_big_bar_level_lines);
z4.SetStyle(Curve.MEDIUM_DASH);


# --------------------------
# test stuff

input test_vertical_lines = no;
addverticalline(test_vertical_lines and insideup, "-", color.green);
addverticalline(test_vertical_lines and insidedown, "-", color.red);

#


wick levels
sArYkOR.jpg
 
i am not sure of your inside bar formula. ( maybe it's too late)
i left it in , but disabled it, so you could re-enable it if you want to.
i added my own inside bar formula.

patched code from post#2

i loaded my code from post2 and noticed sometimes there were lines at 0 during the first few bars.
i added a check , if barnumber 1 then na


Code:
# inside_updown_box_mod01b

# https://usethinkscript.com/threads/inside-and-up-down-box.11130/
# Inside and Up/Down box


input candle_levels = {default "wick" , "body" };
input show_big_bar_level_lines = yes;

def bn = barnumber();
def na = double.nan;

# choose price levels for inside bar , wicks or body
def highx;
def lowx;
def t;
switch (candle_levels) {
case "wick":
  highx = high;
  lowx = low;
  t = 1;
case "body":
  highx = Max( open, close);
  lowx = Min( open, close);
  t = 2;
}

addlabel(1, "Inside bar based on " + (if t == 1 then "Wick levels" else "Body levels"), color.yellow);


# ?? original code ,  body inside bar ?
#def insideBar = close < close[1] and close > open[1] or close < open[1] and close > close[1];

# 'normal' inside bar formula , wicks
#def insideBar = low[1] < low and high[1] > high;

def insideBar = lowx[1] < lowx and highx[1] > highx;

def InsideUp = insideBar[1] and close > highx[1] ;
def InsideDown = insideBar[1] and close < lowx[1] ;

def uphi = if bn == 1 then na else if InsideUp then highx[1] else if InsideUp[-1] then na else uphi[1];
def uplo = if bn == 1 then na else if InsideUp then lowx[1] else if InsideUp[-1] then na else uplo[1];
def dwnhi = if bn == 1 then na else if Insidedown then highx[1] else if Insidedown[-1] then na else dwnhi[1];
def dwnlo = if bn == 1 then na else if Insidedown then lowx[1] else if Insidedown[-1] then na else dwnlo[1];

plot zuphi = uphi;
zuphi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zuphi.SetDefaultColor(Color.light_green);
zuphi.hidebubble();

plot zuplo = uplo;
zuplo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zuplo.SetDefaultColor(Color.light_green);
zuplo.hidebubble();

plot zdwnhi = dwnhi;
zdwnhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwnhi.SetDefaultColor(Color.light_red);
zdwnhi.hidebubble();

plot zdwnlo = dwnlo;
zdwnlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwnlo.SetDefaultColor(Color.light_red);
zdwnlo.hidebubble();

addcloud(zuphi, zuplo, color.green, color.light_green);
addcloud(zdwnhi, zdwnlo, color.red, color.light_red);


# -------------------------
# show lines from mother bar ,big bar

def x = 4;
def biguphi = if bn == 1 then na else if InsideUp[-2] then highx[0] else if InsideUp[x] then na else biguphi[1];
def biguplo = if bn == 1 then na else if InsideUp[-2] then lowx[0] else if InsideUp[x] then na else biguplo[1];
def bigdwnhi = if bn == 1 then na else if Insidedown[-2] then highx[0] else if Insidedown[x] then na else bigdwnhi[1];
def bigdwnlo = if bn == 1 then na else if Insidedown[-2] then lowx[0] else if Insidedown[x] then na else bigdwnlo[1];

plot z1 = biguphi;
plot z2 = biguplo;
plot z3 = bigdwnhi;
plot z4 = bigdwnlo;

z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1.SetDefaultColor(Color.lime);
z1.hidebubble();
z1.SetHiding(!show_big_bar_level_lines);
z1.SetStyle(Curve.MEDIUM_DASH);

z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetDefaultColor(Color.lime);
z2.hidebubble();
z2.SetHiding(!show_big_bar_level_lines);
z2.SetStyle(Curve.MEDIUM_DASH);

z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3.SetDefaultColor(Color.magenta);
z3.hidebubble();
z3.SetHiding(!show_big_bar_level_lines);
z3.SetStyle(Curve.MEDIUM_DASH);

z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetDefaultColor(Color.magenta);
z4.hidebubble();
z4.SetHiding(!show_big_bar_level_lines);
z4.SetStyle(Curve.MEDIUM_DASH);


# --------------------------
# test stuff

addchartbubble(0, low,
 biguphi + "\n" +
 biguplo + "\n" +
 bigdwnhi + "\n" +
 bigdwnlo
, color.yellow, no);

input test_vertical_lines = no;
addverticalline(test_vertical_lines and insideup, "-", color.green);
addverticalline(test_vertical_lines and insidedown, "-", color.red);

#
 
Solution
Can you help me code a variation of this. I measure inside and up breakouts from the top of the body to the bottom of the wick for my box.

i can try, but i don't understand, you will have to write out the rules , what happens , then do what?

are you saying, after an inside bar,
look for a bar with a low that is higher than the previous bar body top?
 
I also wanted them to extend all the way to the right if they have not been broken through yet. I see these as supply and demand levels for intraday trading and targets.
 
i can try, but i don't understand, you will have to write out the rules , what happens , then do what?

are you saying, after an inside bar,
look for a bar with a low that is higher than the previous bar body top?
posted the strategy in the image above. The green drawing is how I use the strategy and am trying to get the script to act on.
 
posted the strategy in the image above. The green drawing is how I use the strategy and am trying to get the script to act on.

that picture helped to visualize what you want.
but it's hard to see what the horizontal lines are lining up with.
need to think in terms of defining the exact price levels, that can be used in formulas and write them out. (define a bar and a price level)

some guesses,
green top = inside bar , high
green bottom = inside bar , low


1. which bar and price level determine blue dash line? ( buy short level)
2. what determines green lines, my zone levels
3. do you want a shaded area between the green lines?
4. why is there a gray rectangle ? if it is to be drawn, what determines the top and bottom of it? what determines which bars to draw it on?
5. what determine red dash line? ( short stop)
6. what determines the target?
 
def insideBar = close < close[1] and close > open[1] or close < open[1] and close > close[1];
def InsideUp = insideBar[1] and close > high[1] ;
def InsideDown = insideBar[1] and close < low[1] ;

I'm trying to get TOS to plot a green box over any inside and ups that extends all the way to the right. vice versa for the inside and downs with a red highlighted box. Can anyone help me with that real quick? I want it to look like mobius pivot lines indicator boxes.
I think you are talking about Trend pivots from Mobius
 
that picture helped to visualize what you want.
but it's hard to see what the horizontal lines are lining up with.
need to think in terms of defining the exact price levels, that can be used in formulas and write them out. (define a bar and a price level)

some guesses,
green top = inside bar , high
green bottom = inside bar , low


1. which bar and price level determine blue dash line? ( buy short level)
2. what determines green lines, my zone levels
3. do you want a shaded area between the green lines?
4. why is there a gray rectangle ? if it is to be drawn, what determines the top and bottom of it? what determines which bars to draw it on?
5. what determine red dash line? ( short stop)
6. what determines the target?
Sorry for the confusion - the only lines I wanted to show you were the green I drew.

1. SO the green lines i drew- If its a bearish set up like in the photo - Bottom of the body of the first candle is first green line - top of the wick for the inside candle is the second green line. This would create a shaded area and remain shaded on the chart until buyers absorb the level. The same goes in reverse for a bullish set up.

There is no target since for me these are supply and demand levels. I identify them on my chart and use them as pivots. my targets would be the next supply or demand zone.
 
that picture helped to visualize what you want.
but it's hard to see what the horizontal lines are lining up with.
need to think in terms of defining the exact price levels, that can be used in formulas and write them out. (define a bar and a price level)

some guesses,
green top = inside bar , high
green bottom = inside bar , low


1. which bar and price level determine blue dash line? ( buy short level)
2. what determines green lines, my zone levels
3. do you want a shaded area between the green lines?
4. why is there a gray rectangle ? if it is to be drawn, what determines the top and bottom of it? what determines which bars to draw it on?
5. what determine red dash line? ( short stop)
6. what determines the target?
This is an image of a30m SPX chart. I drew a bullish and bearish set up. Note that price hasn't broken either of these yet so they remain supply and deman.
 
that picture helped to visualize what you want.
but it's hard to see what the horizontal lines are lining up with.
need to think in terms of defining the exact price levels, that can be used in formulas and write them out. (define a bar and a price level)

some guesses,
green top = inside bar , high
green bottom = inside bar , low


1. which bar and price level determine blue dash line? ( buy short level)
2. what determines green lines, my zone levels
3. do you want a shaded area between the green lines?
4. why is there a gray rectangle ? if it is to be drawn, what determines the top and bottom of it? what determines which bars to draw it on?
5. what determine red dash line? ( short stop)
6. what determines the target?
we're you able to check out the above^?
 
Sorry for the confusion - the only lines I wanted to show you were the green I drew.

1. SO the green lines i drew- If its a bearish set up like in the photo - Bottom of the body of the first candle is first green line - top of the wick for the inside candle is the second green line. This would create a shaded area and remain shaded on the chart until buyers absorb the level. The same goes in reverse for a bullish set up.

There is no target since for me these are supply and demand levels. I identify them on my chart and use them as pivots. my targets would be the next supply or demand zone.

here is a study that follows the rules in post12
it draws green lines and red lines, separately

Code:
# inside_and_down_00

# https://usethinkscript.com/threads/inside-and-up-down-box.11130
# post12
#  the only lines I wanted to show you were the green I drew.

# 1. bearish set up , red lines
#  -- top of the wick of the inside candle 
#  -- Bottom of the body of the candle before inside

# 2. bullish set up , green lines
#  -- bottom of the wick of the inside
#  -- top of the body of the candle before inside

#==========================================

def na = double.nan;
def bn = barnumber();

def isred = (close < open);
def isgreen = (close > open);
def inside = (high < high[1] and low > low[1]);

#------------------------------
# up
def upzonetop;
def upzonebtm;
if bn == 1 or isnan(close) then {
   upzonetop = na;
   upzonebtm = na;
} else if close[0] crosses below upzonebtm[1] then {
# cancel up
   upzonetop = na;
   upzonebtm = na;
} else if (inside[1] and isgreen[2] and close crosses above high[1]) then {
# up
   upzonetop = max(open[2], close[2]);
   upzonebtm = low[1];
} else {
   upzonetop = upzonetop[1];
   upzonebtm = upzonebtm[1];
}

#------------------------------
# down

def dwnzonetop;
def dwnzonebtm;
if bn == 1 or isnan(close) then {
   dwnzonetop = na;
   dwnzonebtm = na;
} else if close[0] crosses above dwnzonetop[1] then {
# cancel down
   dwnzonetop = na;
   dwnzonebtm = na;
} else if (inside[1] and isred[2] and close crosses below low[1]) then {
# down
   dwnzonetop = high[1];
   dwnzonebtm = min(open[2], close[2]);
} else {
   dwnzonetop = dwnzonetop[1];
   dwnzonebtm = dwnzonebtm[1];
}

#---------------------------

plot zut = upzonetop;
plot zub = upzonebtm;
zut.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zub.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zut.SetDefaultColor(Color.green);
zub.SetDefaultColor(Color.green);
zut.setlineweight(1);
zub.hidebubble();

plot zdt = dwnzonetop;
plot zdb = dwnzonebtm;
zdt.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdb.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdt.SetDefaultColor(Color.red);
zdb.SetDefaultColor(Color.red);
zdt.setlineweight(1);
zdb.hidebubble();

addcloud(zut, zub, color.green, color.magenta);
addcloud(zdt, zdb, color.red, color.magenta);
#
#

shows red lines stopping when price crossed above zone high
shows green lines stopping when price crosses below zone low
iDeRvJF.jpg
 
here is a study that follows the rules in post12
it draws green lines and red lines, separately

Code:
# inside_and_down_00

# https://usethinkscript.com/threads/inside-and-up-down-box.11130
# post12
#  the only lines I wanted to show you were the green I drew.

# 1. bearish set up , red lines
#  -- top of the wick of the inside candle
#  -- Bottom of the body of the candle before inside

# 2. bullish set up , green lines
#  -- bottom of the wick of the inside
#  -- top of the body of the candle before inside

#==========================================

def na = double.nan;
def bn = barnumber();

def isred = (close < open);
def isgreen = (close > open);
def inside = (high < high[1] and low > low[1]);

#------------------------------
# up
def upzonetop;
def upzonebtm;
if bn == 1 or isnan(close) then {
   upzonetop = na;
   upzonebtm = na;
} else if close[0] crosses below upzonebtm[1] then {
# cancel up
   upzonetop = na;
   upzonebtm = na;
} else if (inside[1] and isgreen[2] and close crosses above high[1]) then {
# up
   upzonetop = max(open[2], close[2]);
   upzonebtm = low[1];
} else {
   upzonetop = upzonetop[1];
   upzonebtm = upzonebtm[1];
}

#------------------------------
# down

def dwnzonetop;
def dwnzonebtm;
if bn == 1 or isnan(close) then {
   dwnzonetop = na;
   dwnzonebtm = na;
} else if close[0] crosses above dwnzonetop[1] then {
# cancel down
   dwnzonetop = na;
   dwnzonebtm = na;
} else if (inside[1] and isred[2] and close crosses below low[1]) then {
# down
   dwnzonetop = high[1];
   dwnzonebtm = min(open[2], close[2]);
} else {
   dwnzonetop = dwnzonetop[1];
   dwnzonebtm = dwnzonebtm[1];
}

#---------------------------

plot zut = upzonetop;
plot zub = upzonebtm;
zut.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zub.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zut.SetDefaultColor(Color.green);
zub.SetDefaultColor(Color.green);
zut.setlineweight(1);
zub.hidebubble();

plot zdt = dwnzonetop;
plot zdb = dwnzonebtm;
zdt.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdb.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdt.SetDefaultColor(Color.red);
zdb.SetDefaultColor(Color.red);
zdt.setlineweight(1);
zdb.hidebubble();

addcloud(zut, zub, color.green, color.magenta);
addcloud(zdt, zdb, color.red, color.magenta);
#
#

shows red lines stopping when price crossed above zone high
shows green lines stopping when price crosses below zone low
View attachment 16011
Can you create the middle line between high and low of the box? and can you make an option for MTF? Thank you
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
501 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