Watchlist value matching background color


Category:
0
0

Hi Pete.  I am trying to create a column that simply shows if a stock is above or below the VWAP. If above the VWAP the background color will appear green with a green “1” as the label. If below the VWAP the background color will appear red with a red “-1”.  I added the label so it will be easy to sort the watchlist.  I would rather not see the 1 and -1 but simply have the ability to sort the watchlist. Is it possible to have the color of the label to match the background color? Do you have any suggestions?  Thanks for all of your help over the past week, it’s much appreciated.

Marked as spam
Posted by (Questions: 19, Answers: 18)
Asked on August 21, 2024 6:36 pm
38 views
0
Private answer

The simplest solution is to  display the values using a plot statement instead an AddLabel() statement. Then, on that plot statement, apply the same exact if/then/else structure you are using to color the background.

The way you attempted to apply color to the values of your AddLabel() statement is not correct. The AddLabel() statement takes three parameters:

  1. bool: display yes/no
  2. string: value to display
  3. double: color to use for values

You tried to combine the color and the values in the parameter 2. When you should have stuck with only string values in parameter 2 and then assigned the colors in parameter 3. This is how you might correct that error:

AddLabel(yes, if bullish then "1" else if bearish then "-1" else " " , if bullish then Color.GREEN else if bearish then Color.RED else Color.CURRENT);

But like I said, it is much easier to use a plot statement to display the value and then use the AssignValueColor() statement on that plot. Like so:

def bullish = close is greater than reference VWAP()."VWAP";
def bearish = close is less than reference VWAP()."VWAP";
plot data = if bullish then 1 else if bearish then -1 else 0;
data.AssignValueColor(if bullish then Color.GREEN else if Bearish then Color.RED else Color.BLACK);
AssignBackgroundColor(if bullish then Color.GREEN else if bearish then Color.RED else Color.BLACK);

See how simple that is? You use the same exact if/then/else structure for both the AssignValueColor on the plot as well as the AssignBackgroundColor statements.

And please note the last two lines in your example code were not being used at all and they can be deleted no matter which solution you choose.

Marked as spam
Posted by (Questions: 37, Answers: 4108)
Answered on August 21, 2024 6:54 pm
0
Perfect! Thank you very much for your help!
( at August 21, 2024 7:59 pm)