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,728 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Need help with if else

  #1 (permalink)
 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 Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Is there a way to simulate CONTINUOUS CONTRACT?
NinjaTrader
Strategy stop orders partially filled
EasyLanguage Programming
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Funded Trader platforms
35 thanks
Spoo-nalysis ES e-mini futures S&P 500
16 thanks
GFIs1 1 DAX trade per day journal
15 thanks
The Trading Pit "Futures VIP" Account Journal
15 thanks
Trading with Intuition
14 thanks
  #2 (permalink)
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.

Reply With Quote
  #3 (permalink)
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);

Reply With Quote




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