• The price of VIP membership is increasing to $199 beginning June 1. Click here to lock in the current rate of $149.

Show "Yes" or "No" in watchlist column with different background colors

lmk99

Member
VIP
Hi all,

I have labels showing in custom quotes using if/then/else, like this:

Code:
Addlabel(yes, if VARIABLENAME > 0 then "Yes" else "No");

What I want to do is something like this:

Code:
Addlabel(yes, if VARIABLENAME > 0 then "Yes" and Color.GREEN else "No" and Color.RED);

That doesn't work and I can't figure out any way to make it work. I know it's possible to set a color regardless of the if/then/else conditions (doing so when displaying a string value makes the text font have that color). I also know there are examples where the color changes when showing a value (like if the value returned by a formula is positive the number is green, if negative the number is red). But I can't find examples where the color coding is combined with specification of the string value. Does anyone know how to do it?
 

rad14733

Well-known member
VIP
You're close...

Review AddLabel for a better understanding... There are three parameters for the function call and you are attempting to include the data for all three in just two... You have to use the same conditional logic for both the text and the color parameters...

Code:
AddLabel(boolean visible, Any text, CustomColor color);
 

lmk99

Member
VIP
@rad14733 Hi, thanks for your reply. Are you saying that this will work?

Code:
Addlabel(yes, if VARIABLENAME > 0 then "Yes", Color.GREEN);
Addlabel(yes, if VARIABLENAME < 0 then "No", Color.RED);

I think that won't work because I need an "else" condition in each Addlabel code bit. But I can't get the color labels to be included in the if / else conditions.
 

rad14733

Well-known member
VIP
Or you can do it with the same conditional for both variables in one call...

Code:
Addlabel(yes, if VARIABLENAME > 0 then "Yes" else "No", if VARIABLENAME > 0 then Color.GREEN else Color.RED (y) );

I try to give enough help so folks can learn to Thinkscript rather than simply handing out code... You were VERY close...
 

RickAns

Active member
VIP
That is really good to know, @rad14733 . Did not realize it was possible to do more than one 'if' in an AddLabel, etc line. My attempt would have been an 'else Double.NaN' in post #3 at then end of each line. Which may not have been the correct way to do it.
 

Similar threads

Top