Show or Hide AddCloud() Function

Daedalus77

New member
The AddCloud function in thinkScript lets you connect two plots and fill them with a translucent background color. My question is: does anyone know if there is a way to give users the option to selectively hide or reveal clouds generated with the AddCloud() function?
 
Solution
The easiest way to do so is to add an input selector which adds as a toggle switch to either display clouds or not. Here is an example code that displays cloud between two dates, run this on a daily aggregation. To turn the cloud off, go into the user interface and set the input selector to the variable "showCloud" to no.

Code:
# Displays cloud between two dates 

declare hide_on_intraday;

input showCloud = yes;

input Day1 = 20191103;
input Day2 = 20191208;

plot cond1 = if GetYYYYMMDD() >= Day1 and GetYYYYMMDD() <= Day2 then double.positive_infinity else double.nan;
plot cond2 = if GetYYYYMMDD() <= Day2 and GetYYYYMMDD() >= Day1 then double.negative_infinity else double.nan;

AddCloud(if showCloud then cond1 else Double.NaN, cond2...
The easiest way to do so is to add an input selector which adds as a toggle switch to either display clouds or not. Here is an example code that displays cloud between two dates, run this on a daily aggregation. To turn the cloud off, go into the user interface and set the input selector to the variable "showCloud" to no.

Code:
# Displays cloud between two dates 

declare hide_on_intraday;

input showCloud = yes;

input Day1 = 20191103;
input Day2 = 20191208;

plot cond1 = if GetYYYYMMDD() >= Day1 and GetYYYYMMDD() <= Day2 then double.positive_infinity else double.nan;
plot cond2 = if GetYYYYMMDD() <= Day2 and GetYYYYMMDD() >= Day1 then double.negative_infinity else double.nan;

AddCloud(if showCloud then cond1 else Double.NaN, cond2, color.red, color.red);
 
Solution
@tomsk Thank you.

For anyone interested in using AddCloud in their code here's an example.

Code:
#   DMonkey 8/20/2017
#   Adds a cloud at defined market times as per user inputs
#   This does NYC Market time, you can rinse and repeat for other market time
#   13:01 jeremy0306: Anyone know of any scripts that highlight the different market times.So for example when the london exhange is      open it wouild highlight the time on the screen one color and then when NY opens it will highlight that portion, etc.

input start = 0930;
input end = 1600;

def h = double.POSITIVE_INFINITY;
def hh = if secondsFromTime(start) == 0
         then h
         else hh[1];

plot Opening_High = if secondsFromTime(start) >= 0 &&
                       secondsFromTime(end) < 0
                    then hh
                    else double.nan;
opening_High.setdefaultColor(createColor(204,153,255));

def l = double.NEGATIVE_INFINITY;
def ll = if secondsFromTime(start) == 0
         then l
         else ll[1];

plot Opening_Low = if secondsFromTime(start) >= 0 &&
                      secondsFromTime(end) < 0
                   then ll
                   else double.nan;
opening_Low.setdefaultColor(createColor(204,153,255));

addcloud(opening_Low,Opening_High, color2 = createColor(204,153,255));

#   End Code
 
I sure wish that the AddCloud function had a permissive built in such as AddLabel. This would allow you to turn the Cloud on and off at will.

I have found a work around, though. I just have the cloud assume the background color using this code:

input showCloud = yes;
AddCloud(Ratio, 1, if showCloud then color.Green else color.black, if showCloud then color.red else color.black);

This works.

Hope this helps someone out there!
 
How can I add an input where I can turn on and off the cloud color?
for example: [Show Cloud: Yes/No]

Code:
input Length1 = 72;
input Length2 = 89;
input Period = AggregationPeriod.THREE_MIN;
input averageType = AverageType.EXPONENTIAL;
input CloudColorBull = {"WHITE", "LIGHT_GRAY", default "GRAY", "GREEN", "RED", "ORANGE", "MAGENTA", "CYAN", "PINK"};
input CloudColorBear = {"WHITE", "LIGHT_GRAY", default "GRAY", "GREEN", "RED", "ORANGE", "MAGENTA", "CYAN", "PINK"};

plot EMA1 = MovingAverage(averageType, close(period = period), length1);
plot EMA2 = MovingAverage(averageType, close(period = period), length2);

#AddCloud(EMA1,EMA2,GetColor(CloudColorBull),GetColor(CloudColorBear));
 
@Robby Luca
Code:
input Length1 = 72;
input Length2 = 89;
input Period = AggregationPeriod.THREE_MIN;
input averageType = AverageType.EXPONENTIAL;
input show_cloud = yes;

DefineGlobalColor("Bullish Cloud", color.GREEN);
DefineGlobalColor("Bearish Cloud", color.RED);

plot EMA1 = MovingAverage(averageType, close(period = period), length1);
plot EMA2 = MovingAverage(averageType, close(period = period), length2);

AddCloud(if show_cloud then EMA1 else double.nan,EMA2,GlobalColor("Bullish Cloud"),GlobalColor("Bearish Cloud"));
 
Last edited:
@Pensar Thank you. The on and off toggle works, but I am getting another issue now. The cloud does not match the colors I selected. As shown in the image, I have Light Gray selected, but it has a green cloud. I have tried all the colors and they are all random colors.

88izRHl.png
 
@Robby Luca For some reason, I cannot seem to find why the colors as originally coded will not plot correctly; someone more experienced may know why.

I have updated the code in my post above by slightly changing the coding for the colors and placing them under the Globals tab. You should be now able to choose whichever color you want from the properties. The Globals tab is below the Plots tab in the properties settings. Hopefully this will work for you.
 
@Pensar Still isn't working. Also, trying with no bull/bear, a new version just 1 color but it is not working. "AddCloud" is giving an error.

Code:
input length1 = 72;
input length2 = 89;
input period = AggregationPeriod.THREE_MIN;
input averageType = AverageType.EXPONENTIAL;
input show_cloud = yes;

input CloudColor = {"WHITE", "LIGHT_GRAY", default "GRAY", "GREEN", "RED", "ORANGE", "MAGENTA", "CYAN", "PINK"};

plot EMA1 = MovingAverage(averageType, close(period = period), length1);
plot EMA2 = MovingAverage(averageType, close(period = period), length2);

AddCloud(yes, GetColor(CloudColor));
 
@Robby Luca As an explanation of my earlier post about moving the colors to the Globals tab -

QihiJ78.png


I dont keep codes very long; but this should be an exact copy of what I originally posted. It has the same coloring issue as the original.

Code:
# FAULTY CODE - DO NOT USE

input Length1 = 72;
input Length2 = 89;
input Period = AggregationPeriod.THREE_MIN;
input averageType = AverageType.EXPONENTIAL;
input CloudColorBull = {"WHITE", "LIGHT_GRAY", default "GRAY", "GREEN", "RED", "ORANGE", "MAGENTA", "CYAN", "PINK"};
input CloudColorBear = {"WHITE", "LIGHT_GRAY", default "GRAY", "GREEN", "RED", "ORANGE", "MAGENTA", "CYAN", "PINK"};
input show_cloud = yes;

plot EMA1 = MovingAverage(averageType, close(period = period), length1);
plot EMA2 = MovingAverage(averageType, close(period = period), length2);

AddCloud(if show_cloud then EMA1 else double.nan,EMA2,GetColor(CloudColorBull),GetColor(CloudColorBear));

You mentioned that AddCloud() is giving an error in your code. It needs upper and lower variables or plots to work. Here are examples - https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddCloud - adding those should remove the AddCloud error. ;)
 
I spent all weekend working on customizing my script with clouds to indicate different conditions being met or unmet, using AddCloud. The clouds appeared on the chart (because the conditions were true/false, the clouds appeared as vertical pillars running from the top to the bottom of the chart, which is the same effect as plotting a histogram on the upper price chart using SetPaintingStrategy instead of plotting arrows for example).

Around 15 minutes ago, although I didn't change anything in the script, the clouds stopped appearing. I can think of several possibilities that may explain this but I don't know which if any are correct, hoping someone here knows:

1) The script is very complex and it works / loads fine when the market is closed, but won't ever work when the market is open because ThinkOrSwim's server capacity can't accommodate the complexity of the script in realtime.

2) The script will work during normal market hours, but for some reason scripts don't always run correctly during premarket hours or in the early morning.

3) The script would be working fine during normal market hours if my computer was faster (it's quite old) - in other words, my computer is a bottleneck, not the ThinkOrSwim platform itself.

Has anyone experienced this issue before where a script works during the weekend while testing but some parts of it (such as clouds) stop working when premarket opens? It's quite frustrating that I spent all this time and the code is correct but the cloud part of the script just won't run, although the rest of it runs. I find it baffling. I tried deleting every study and having only one cell open, and changing the time span to just one day, with just that study running, in case that would make a difference but it didn't.

PS: This is the bizarre part, all of the arrows plot correctly, and I tested changing one of the arrows from "PAINTINGSTRATEGY.BOOLEAN_ARROW_UP" to "PAINTINGSTRATEGY.HISTOGRAM" and "SQUARED_HISTOGRAM" and the plot disappears. So it's only histogram plots and clouds that aren't showing up on the price chart even though they worked during the weekend.

I'm wondering if the reason for this is that HISTOGRAM, SQUARED HISTOGRAM, and CLOUD aren't supposed to be used with boolean values to appear as pillars of color - might that be the case? But that is how I need to use them for what I'm trying to do. I don't see any reason why it shouldn't be supported to create color pillars on the upper chart.
 
Last edited:
On 'rare occasions, I have had problems with watchlists and custom scripts going kerflooey at 3 am. I think it is when they push updates through the system. And the end of the weekend seems to be when it happens most often. The 1st clue is when charts start taking many minutes to load and then things are just 'not right' which started to happen at 3 am this morning.

I figure it's TD's way of telling me to go to bed. When I get up, things usually look better, if not then I at least know it's a scripting error on my part and not the random 3 am nonsense that sometimes occurs. HTH
 
This post showed up in a google search for creating a toggle for clouds on an indicator so I'll add the code that I used as a solution for making the clouds toggle-able on my own indicator. I've removed the rest of my code and only included the code relevant to showing/hiding the cloud.

INI:
input showcloud = yes;

def cloudh1 = if showcloud == yes then h1 else double.nan;
def cloudh2 = if showcloud == yes then h2 else double.nan;
def cloud l1 = if showcloud == yes then l1 else double.nan;
def cloudl2 = if showcloud == yes then l2 else double.nan;

Addcloud(cloudh2, cloudh1, color.red);
Addcloud(cloudl1, cloudl2, color.green);
 
Last edited:

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
313 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