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:
- bool: display yes/no
- string: value to display
- 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.