Inside Bar Outside Bar Clouds For ThinkOrSwim

Laylabrador

New member
i am trying to add a cloud between the two vertical lines. I am able to put the vertical lines but not the cloud. How can I do that?

plot inbar = low > low[1] and high < high[1];
plot outbar = low < low[1] and high > high[1];
plot holygrail = outbar[1] and inbar;

AssignPriceColor(if (inbar and !holygrail) then Color.YELLOW else Color.CURRENT);
AssignPriceColor(if (outbar and !holygrail) then Color.BLACK else Color.CURRENT);

AddVerticalLine(holygrail, "InBar", Color.ORANGE, Curve.FIRM);

AddVerticalLine(holygrail[-1], "OUTBar", Color.WHITE, Curve.FIRM);

AddVerticalLine(holygrail[+1], "HolyGrail", Color.RED, Curve.FIRM);
 

SleepyZ

Well-known member
VIP
Lifetime
Inside Bar Outside Bar Clouds For ThinkOrSwim

TOS's 'addcloud' function does not work very well drawing clouds between vertical lines as the clouds do not align within the vertical lines. A workaround is to use the 'unsupported', but available to use 'addchart' function.

Capture.jpg
Ruby:
plot inbar = low > low[1] and high < high[1];
plot outbar = low < low[1] and high > high[1];
plot holygrail = outbar[1] and inbar;

AssignPriceColor(if (inbar and !holygrail) then Color.YELLOW else Color.CURRENT);
AssignPriceColor(if (outbar and !holygrail) then Color.BLACK else Color.CURRENT);

AddVerticalLine(holygrail, "InBar", Color.ORANGE, Curve.FIRM);

AddVerticalLine(holygrail[-1], "OUTBar", Color.WHITE, Curve.FIRM);

AddVerticalLine(holygrail[+1], "HolyGrail", Color.RED, Curve.FIRM);

#########################
#Workaround Cloud between vertical lines using addchart()

def h = Double.POSITIVE_INFINITY;
def l = Double.NEGATIVE_INFINITY;
def xoutbar  = if holygrail[-1] and outbar then 1 else 0;
def xinbar   = if holygrail     and inbar  then 1 else 0;
def xboth    = if xoutbar == 1
               then 1 else
               if xboth[1] == 1 and xinbar == 1
               then 1 else 0;

input cloud = {default out_in, out_holygrail, in_holygrail, NONE};

def xH =     if cloud == cloud.NONE
             then Double.NaN else
             if cloud == cloud.out_in        and xoutbar  == 1  or
                cloud == cloud.out_holygrail and xboth or 
                cloud == cloud.in_holygrail  and xinbar   == 1
             then h else Double.NaN;
def xL =     if cloud == cloud.NONE
             then Double.NaN else
             if cloud == cloud.out_in        and xoutbar == 1 or
                cloud == cloud.out_holygrail and xboth or
                cloud == cloud.in_holygrail  and xinbar  == 1
             then l else Double.NaN;

AddChart(high = xH, low = xL, open = xH, close = xL, type = ChartType.CANDLE, growColor = Color.LIGHT_GRAY);

##########################
#Display candles hidden by above workaround
def rh =     if cloud == cloud.NONE
             then Double.NaN else
             if cloud == cloud.out_in        and xoutbar == 1 or
                cloud == cloud.out_holygrail and xboth or
                cloud == cloud.in_holygrail  and xinbar  == 1
             then high else Double.NaN;

def rl =     if cloud == cloud.NONE
             then Double.NaN else
             if cloud == cloud.out_in        and xoutbar == 1 or
                cloud == cloud.out_holygrail and xboth or
                cloud == cloud.in_holygrail  and xinbar  == 1
             then low else Double.NaN;
def rhg = if close >= open then rh else Double.NaN;
AddChart(high = rhg, low = rl, open = close, close = open, growColor = Color.GREEN, type = ChartType.CANDLE);

def rhr = if close < open then rh else Double.NaN;
AddChart(high = rhr, low = rl, open = open, close = close, growColor = Color.RED, type = ChartType.CANDLE);
 
Last edited by a moderator:

Emp1011

New member
Hello, can any one add clouds like this on TOS i have the script for it (inside bars, and outside bars) i just can seem to figure it out.
here's the script for TOS

plot Data = close;
plot one = if low >= low[1]
and high <= high[1]
then 1 else Double.NaN;
one.SetDefaultColor(Color.WHITE);
one.SetPaintingStrategy(PaintingStrategy.valueS_BELOW);

plot two = if high > high[1]
and low >= low[1]
or high <= high[1]
and low < low[1]
then 2 else Double.NaN;
two.SetDefaultColor(Color.WHITE);
two.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot three = if high > high[1]
and low < low[1]
then 3 else Double.NaN;
three.SetDefaultColor(Color.WHITE);
three.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

AssignPriceColor(if one then Color.BLUE else Color.CURRENT);

AssignPriceColor(if three then Color.PLUM else Color.CURRENT);



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.squaRED_HISTOGRAM);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);

XCc8aZBT
 

SleepyZ

Well-known member
VIP
Lifetime
Hello, can any one add clouds like this on TOS i have the script for it (inside bars, and outside bars) i just can seem to figure it out.
here's the script for TOS

plot Data = close;
plot one = if low >= low[1]
and high <= high[1]
then 1 else Double.NaN;
one.SetDefaultColor(Color.WHITE);
one.SetPaintingStrategy(PaintingStrategy.valueS_BELOW);

plot two = if high > high[1]
and low >= low[1]
or high <= high[1]
and low < low[1]
then 2 else Double.NaN;
two.SetDefaultColor(Color.WHITE);
two.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot three = if high > high[1]
and low < low[1]
then 3 else Double.NaN;
three.SetDefaultColor(Color.WHITE);
three.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

AssignPriceColor(if one then Color.BLUE else Color.CURRENT);

AssignPriceColor(if three then Color.PLUM else Color.CURRENT);



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.squaRED_HISTOGRAM);
hg2.SetDefaultColor(Color.white);
hg2.setlineweight(3);

XCc8aZBT

This script that I posted before might help https://usethinkscript.com/threads/adding-a-cloud-between-two-bars.7208/post-69518
 

jflores0002

New member
That works. I took your script and played with it. Masked the labels and the actual vertical lines since I didn't like the look. Can the vertical cloud be transparent and adjustable? I also made the labels opacity adjustable....

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;


# 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;
DefineGlobalColor("IB", Color.yellow);
DefineGlobalColor("OB", Color.blue);
addchartbubble(inbar, (high * (1 + bubble_ht_offset)), "IB", GlobalColor("IB"));
addchartbubble(outbar, (low * (1 - bubble_ht_offset)), "OB", GlobalColor("OB"));
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);


AssignPriceColor(if (inbar and !holygrail) then Color.YELLOW else Color.CURRENT);
AssignPriceColor(if (outbar and !holygrail) then Color.Blue else Color.CURRENT);

#AddVerticalLine(holygrail, "InBar", Color.ORANGE, Curve.FIRM);

#AddVerticalLine(holygrail[-1], "OUTBar", Color.WHITE, Curve.FIRM);

#AddVerticalLine(holygrail[+1], "HolyGrail", Color.RED, Curve.FIRM);

#########################
#Workaround Cloud between vertical lines using addchart()

def h = Double.POSITIVE_INFINITY;
def l = Double.NEGATIVE_INFINITY;

def xoutbar = if holygrail[-1] and outbar then 1 else 0;
def xinbar = if holygrail and inbar then 1 else 0;
def xboth = if xoutbar == 1
then 1 else
if xboth[1] == 1 and xinbar == 1
then 1 else 0;

input cloud = {default out_in, out_holygrail, in_holygrail, NONE};

def xH = if cloud == cloud.NONE
then Double.NaN else
if cloud == cloud.out_in and xoutbar == 1 or
cloud == cloud.out_holygrail and xboth or
cloud == cloud.in_holygrail and xinbar == 1
then h else Double.NaN;
def xL = if cloud == cloud.NONE
then Double.NaN else
if cloud == cloud.out_in and xoutbar == 1 or
cloud == cloud.out_holygrail and xboth or
cloud == cloud.in_holygrail and xinbar == 1
then l else Double.NaN;

AddChart(high = xH, low = xL, open = xH, close = xL, type = ChartType.CANDLE, growcolor = Color.light_GREEN);

##########################
#Display candles hidden by above workaround
def rh = if cloud == cloud.NONE
then Double.NaN else
if cloud == cloud.out_in and xoutbar == 1 or
cloud == cloud.out_holygrail and xboth or
cloud == cloud.in_holygrail and xinbar == 1
then high else Double.NaN;

def rl = if cloud == cloud.NONE
then Double.NaN else
if cloud == cloud.out_in and xoutbar == 1 or
cloud == cloud.out_holygrail and xboth or
cloud == cloud.in_holygrail and xinbar == 1
then low else Double.NaN;
def rhg = if close >= open then rh else Double.NaN;
AddChart(high = rhg, low = rl, open = close, close = open, growColor = Color.GREEN, type = ChartType.CANDLE);

def rhr = if close < open then rh else Double.NaN;
AddChart(high = rhr, low = rl, open = open, close = close, growColor = Color.RED, type = ChartType.CANDLE);
 

SleepyZ

Well-known member
VIP
Lifetime
That works. I took your script and played with it. Masked the labels and the actual vertical lines since I didn't like the look. Can the vertical cloud be transparent and adjustable? I also made the labels opacity adjustable....

Sorry, but TOS does not provide opacity functionality for clouds like they do for value areas in profiles e.g.: volume, tpo). The vertical lines in the above script were only shown to help the requestor see that the workaround worked, so I understand how you did not like the look.
 

jflores0002

New member
Okay got it. Just wonder when I load ichimoku it seems to be transparent. Yes, i know it's different script but was hoping there would be a way....
Thanks
 

SleepyZ

Well-known member
VIP
Lifetime
I should have also said. you can adjust the color of a object within the script to be more or less visible by choosing another color.

You can also use as in ichimoku to use global color to adjust the color at the input screen. See below for how the global color modification to the addchart part of the script I posted above. However, regrettably in either method, there is not a transparency option.

Rich (BB code):
defineGlobalColor("Cloud", color.light_gray);
AddChart(high = xH, low = xL, open = xH, close = xL, type = ChartType.CANDLE, growColor = globalcolor("Cloud"));
 

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.
Top