Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I have two variables, MyHigh and MyLow.
I would like to add a cloud with different colors depending on the close price.
This is the statement which is giving me an error.
AddCloud(MyLow, MyHigh, if close > MyHigh then color.DARK_GREEN else if close < MyLow then color.LIGHT_RED else color.YELLOW, if close > MyHigh then color.DARK_GREEN else if close < MyLow then color.LIGHT_RED else color.YELLOW);
Update:
Checked with TDA support. Apparently AddCloud() does not support if/else statement
Can you help answer these questions from other members on NexusFi?
------
Remember, AddCloud will color the area between the 2 values based on which one is greater. Therefore, you'd be way better off using an if/then/else clause based on the current value of close as compared to MyLow/MyHigh...so something like the following should do the trick. As always, you'll need to test & validate that it does what you expect/want.
If close > MyHigh Then AddCloud(MyHigh,MyLow,color.DARK_GREEN,color.YELLOW) Else IF
close < MyLow Then AddCloud(MyHigh,MyLow,color.LIGHT_RED,color.YELLOW) Else AddCloud (MyHigh,MyLow,color.YELLOW,color.YELLOW)
What this should do:
* If Close (aka last tx) is > MyHigh, the cloud should be colored DARK_GREEN.
* IF close <= MyHigh), then test to see if close is < MyLow. If it is, the cloud should be colored LIGHT_RED.
* If Neither condition is true, then the cloud will be colored YELLOW.
optiwatch
Atlanta, GA, US
Posts: 1 since Mar 2020
Thanks Given: 0
Thanks Received: 0
If you need additional colors to visually indicate a condition
, you could change the color of the lines instead of the cloud. I tried two clouds, since I do not know the calculations of your MyHigh/MyLow variables I put the code below but also used a clould based on EMAs. With the cloud, the lines are hard to see, so I set their width to 3.
input showEMACloud = yes;
input showHLCloud = no ;
def ema9 = MovAvgExponential(length = 4);
def ema26 = MovAvgExponential(length = 13);
# cofirmed, "if" logic does not work in AddCloud() does not work, it is expecting a constant only for color
#AddCloud(ema4, ema13, if close > ema4 then Color.DARK_GREEN else if close < ema13 then Color.LIGHT_RED else Color.YELLOW, if close > ema4 then Color.DARK_GREEN else if close < ema13 then Color.LIGHT_RED else Color.YELLOW);
AddCloud(ema9, ema26, Color.GREEN, Color.RED);
plot Pema4 = if showEMACloud then ema9 else Double.NaN;
plot Pema13 = if showEMACloud then ema26 else Double.NaN;
Pema4.assignValueColor(if close > ema9 then Color.DARK_GREEN else if close < ema26 then Color.LIGHT_RED else Color.YELLOW);
Pema13.assignValueColor(if close > ema9 then Color.DARK_GREEN else if close < ema26 then Color.LIGHT_RED else Color.YELLOW);
Pema4.setLineWeight(3);
Pema13.setLineWeight(3);
plot PMyHigh = if showHLCloud then high else Double.NaN;
plot PMyLow = if showHLCloud then low else Double.NaN;
PMyHigh.assignValueColor(if close > PMyHigh then Color.DARK_GREEN else if close < PMyLow then Color.LIGHT_RED else Color.YELLOW);
PMyLow.assignValueColor(if close > PMyHigh then Color.DARK_GREEN else if close < PMyLow then Color.LIGHT_RED else Color.YELLOW);
PMyHigh.setLineWeight(3);
PMyLow.setLineWeight(3);