# Inside Bar OutSide Bar Clouds For ThinkOrSwim

#### dhman06

##### Member
Essentially this is what I'm trying to achieve:
1. Inside Bar followed by Outside Bar [Cloud Shaded Yellow for these 2 bars]
2. Outside Bar followed by Inside Bar [Cloud Shaded Plum for these 2 bars]

Should've been more clear. I'm trying to have vertical stripes on the chart when holygrail conditions are met. Something similar to this:https://www.tradingview.com/script/uYiilgYb-TW-Golden-Indicators/

Last edited by a moderator:
Solution
Is this correct if I'm trying to find the Outside Bar followed by Inside Bar setup?

the code you created to make a cloud, looks good.
to draw a cloud, you need 2 lines, with at least 2 points.
def x = (hg2 or hg2[1]);
x will be true on the bar that hg2 is true, and hg2[1] will be true on the bar after it. which gives us 2 points.

i didn't study the logic of the program, so i'm not sure if hg2 is the 'Outside Bar followed by Inside Bar'.
i know , i made it, but i don't use it. after i'm done with something , i forget about it and go on to the next.

there is a way to draw a bar, in the vertical space of a candle, with addchart(). but that is more involved.
1 example...
Sorry, should've been more clear. I'm trying to have vertical stripes on the chart when holygrail conditions are met. Something similar to this:https://www.tradingview.com/script/uYiilgYb-TW-Golden-Indicators/

I think I have the definition down, but can't get the stripe to show up on the chart. I thought assignbackgroundcolor would've worked, but clearly I'm wrong

i converted the holy grail a few months ago.

maybe this will help.
i added a skinny ( 1 bar wide) cloud to the end of the code, as an example of 1 way to do it.

Ruby:
``````# golden_01c

#// TW Golden Indicators Package
#// This package features BB (with 20 ma), inside bar color change (white), outside bar color change (black), and holy grail 2-candle pattern background higlhlight (yellow)

def lastbar = !isnan(close[0]) and isnan(close[-1]);
def src = close;
input length = 20;
input mult = 2.0;
def mult2 = if mult > 50 then 50 else if mult < 0.001 then 0.001 else mult;

# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#  EXPONENTIAL, HULL, SIMPLE, WEIGHTED, WILDERS
input avg1_type =  AverageType.simple;
def basis = MovingAverage(avg1_type, src, length);
def dev = mult2 * StDev( src , length );
def upper = basis + dev;
def lower = basis - dev;

# horz lines
plot basisLine = highestAll(if isNaN(close[-1]) then basis else Double.NaN);
basisline.SetDefaultColor(Color.red);
basisline.SetStyle(Curve.SHORT_DASH);
plot upperLine = highestAll(if isNaN(close[-1]) then upper else Double.NaN);
upperline.SetDefaultColor(Color.magenta);
plot lowerLine = highestAll(if isNaN(close[-1]) then lower else Double.NaN);
lowerline.SetDefaultColor(Color.magenta);

# inside and outside bars
def inBar = low > low[1] and high < high[1];
def outBar = low < low[1] and high > high[1];
def holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];

input bubble_ht_offset = 0.0006;
addchartbubble(inbar, (high * (1 + bubble_ht_offset)), "IB", color.yellow, yes);
addchartbubble(outbar, (low * (1 - bubble_ht_offset)), "OB", color.blue, no);

def off = 1;
addchartbubble(lastbar[off] and holyGrail[off] and inbar[off], close, "Holy Grail" + "\nInbar", color.yellow, yes);
addchartbubble(lastbar[off] and holyGrail[off] and outbar[off], close, "Holy Grail" + "\nOutbar", color.yellow, yes);

plot hg2 = holygrail;
hg2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_up);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);
#

def x = (inbar or inbar[1]);
def xtop = if x then double.POSITIVE_INFINITY else double.nan;
#``````

Last edited:
i converted the holy grail a few months ago.

maybe this will help.
i added a skinny ( 1 bar wide) cloud the the end of the code, as an example of 1 way to do it.

Ruby:
``````# golden_01c

#// TW Golden Indicators Package
#// This package features BB (with 20 ma), inside bar color change (white), outside bar color change (black), and holy grail 2-candle pattern background higlhlight (yellow)

def lastbar = !isnan(close[0]) and isnan(close[-1]);
def src = close;
input length = 20;
input mult = 2.0;
def mult2 = if mult > 50 then 50 else if mult < 0.001 then 0.001 else mult;

# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#  EXPONENTIAL, HULL, SIMPLE, WEIGHTED, WILDERS
input avg1_type =  AverageType.simple;
def basis = MovingAverage(avg1_type, src, length);
def dev = mult2 * StDev( src , length );
def upper = basis + dev;
def lower = basis - dev;

# horz lines
plot basisLine = highestAll(if isNaN(close[-1]) then basis else Double.NaN);
basisline.SetDefaultColor(Color.red);
basisline.SetStyle(Curve.SHORT_DASH);
plot upperLine = highestAll(if isNaN(close[-1]) then upper else Double.NaN);
upperline.SetDefaultColor(Color.magenta);
plot lowerLine = highestAll(if isNaN(close[-1]) then lower else Double.NaN);
lowerline.SetDefaultColor(Color.magenta);

# inside and outside bars
def inBar = low > low[1] and high < high[1];
def outBar = low < low[1] and high > high[1];
def holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];

input bubble_ht_offset = 0.0006;
addchartbubble(inbar, (high * (1 + bubble_ht_offset)), "IB", color.yellow, yes);
addchartbubble(outbar, (low * (1 - bubble_ht_offset)), "OB", color.blue, no);

def off = 1;
addchartbubble(lastbar[off] and holyGrail[off] and inbar[off], close, "Holy Grail" + "\nInbar", color.yellow, yes);
addchartbubble(lastbar[off] and holyGrail[off] and outbar[off], close, "Holy Grail" + "\nOutbar", color.yellow, yes);

plot hg2 = holygrail;
hg2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_up);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);
#

def x = (inbar or inbar[1]);
def xtop = if x then double.POSITIVE_INFINITY else double.nan;
#``````
Thank you! I'll try it out tomorrow. Really appreciate the help

i converted the holy grail a few months ago.

maybe this will help.
i added a skinny ( 1 bar wide) cloud the the end of the code, as an example of 1 way to do it.

Ruby:
``````# golden_01c

#// TW Golden Indicators Package
#// This package features BB (with 20 ma), inside bar color change (white), outside bar color change (black), and holy grail 2-candle pattern background higlhlight (yellow)

def lastbar = !isnan(close[0]) and isnan(close[-1]);
def src = close;
input length = 20;
input mult = 2.0;
def mult2 = if mult > 50 then 50 else if mult < 0.001 then 0.001 else mult;

# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#  EXPONENTIAL, HULL, SIMPLE, WEIGHTED, WILDERS
input avg1_type =  AverageType.simple;
def basis = MovingAverage(avg1_type, src, length);
def dev = mult2 * StDev( src , length );
def upper = basis + dev;
def lower = basis - dev;

# horz lines
plot basisLine = highestAll(if isNaN(close[-1]) then basis else Double.NaN);
basisline.SetDefaultColor(Color.red);
basisline.SetStyle(Curve.SHORT_DASH);
plot upperLine = highestAll(if isNaN(close[-1]) then upper else Double.NaN);
upperline.SetDefaultColor(Color.magenta);
plot lowerLine = highestAll(if isNaN(close[-1]) then lower else Double.NaN);
lowerline.SetDefaultColor(Color.magenta);

# inside and outside bars
def inBar = low > low[1] and high < high[1];
def outBar = low < low[1] and high > high[1];
def holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];

input bubble_ht_offset = 0.0006;
addchartbubble(inbar, (high * (1 + bubble_ht_offset)), "IB", color.yellow, yes);
addchartbubble(outbar, (low * (1 - bubble_ht_offset)), "OB", color.blue, no);

def off = 1;
addchartbubble(lastbar[off] and holyGrail[off] and inbar[off], close, "Holy Grail" + "\nInbar", color.yellow, yes);
addchartbubble(lastbar[off] and holyGrail[off] and outbar[off], close, "Holy Grail" + "\nOutbar", color.yellow, yes);

plot hg2 = holygrail;
hg2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_up);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);
#

def x = (inbar or inbar[1]);
def xtop = if x then double.POSITIVE_INFINITY else double.nan;
#``````
Thank you again for your response. Instead of inbar, I used hg2 to mimic similar thing. Is this correct if I'm trying to find the Outside Bar followed by Inside Bar setup? Here is what I coded up

def x = (hg2 or hg2[1]);
def xtop = if x then double.POSITIVE_INFINITY else double.nan;

Is this correct if I'm trying to find the Outside Bar followed by Inside Bar setup?

the code you created to make a cloud, looks good.
to draw a cloud, you need 2 lines, with at least 2 points.
def x = (hg2 or hg2[1]);
x will be true on the bar that hg2 is true, and hg2[1] will be true on the bar after it. which gives us 2 points.

i didn't study the logic of the program, so i'm not sure if hg2 is the 'Outside Bar followed by Inside Bar'.
i know , i made it, but i don't use it. after i'm done with something , i forget about it and go on to the next.

there is a way to draw a bar, in the vertical space of a candle, with addchart(). but that is more involved.

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