Turning Clouds on and off...

RmS59

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

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));
 
P

Pensar

Active 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:
R

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.

 
P

Pensar

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

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));
 
R

Robby Luca

New member
@Pensar Yes, but I meant I tried something different. Is it possible to have your initial script that you posted before "DefineGlobalColor". I would like to see something. Thank you!
 
P

Pensar

Active member
VIP
@Robby Luca As an explanation of my earlier post about moving the colors to the Globals tab -

 
P

Pensar

Active member
VIP
@Robby Luca 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. ;)
 
Last edited:

Similar threads

Top