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

tomsk

Well-known member
VIP
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

Daedalus77

New member
@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
 

RmS59

Member
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!
 

Robby Luca

New member
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));
 

Pensar

Well-known member
VIP
@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:

Robby Luca

New member
@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
 

Pensar

Well-known member
VIP
@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.
 

Robby Luca

New member
@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));
 

Pensar

Well-known member
VIP
@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. ;)
 

lmk99

Member
VIP
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:

MerryDay

Administrative
Staff member
Staff
VIP
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
 

Rojo Grande

Member
VIP
I used the above script for my RSI indicator, but it appears to be off by one bar. I have the trigger as the mid_line which is 50. Any help is always appreciated, thank you.


aHJx9MY.png
 

Similar threads

Top