NexusFi: Find Your Edge


Home Menu

 





Need help with if else


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one ColoradoCliff with 1 posts (0 thanks)
    2. looks_two phantomwallet with 1 posts (0 thanks)
    3. looks_3 Mhaus with 1 posts (0 thanks)
    4. looks_4 optiwatch with 1 posts (0 thanks)
    1. trending_up 2,717 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
 

Need help with if else

 
 Mhaus 
Austin, TX
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 9 since Sep 2011
Thanks Given: 2
Thanks Received: 0

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

Started this thread

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
45 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
 
ColoradoCliff
Parker CO/USA
 
Posts: 22 since Jun 2017
Thanks Given: 0
Thanks Received: 5


Mhaus View Post
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

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



Mhaus View Post
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

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


 



Last Updated on March 30, 2022


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts