Display text values in custom watchlist column


Price to Text label field


Hello Pete, 

I wanted to know if it was possible to have a code that displays a color text label RED (NEGATIVE) , GREEN (POSITIVE) instead of price?

Ex. if data < 1.00 then “NEGATIVE” else “POSITIVE”

I’ve been trying to make those changes tot he could below.

Thank you for you help with this.





plot data = close;

AddLabel(yes, round(data,2));

AssignPriceColor(if data >= 1 then color.GREEN else if data <=.5 then Color.MAGENTA else color.Gray);

AddLabel(yes, Round(data, 2), if data < 1.00 then Color.RED else Color.GREEN);

Marked as spam
Posted by (Questions: 3, Answers: 5)
Asked on October 23, 2021 12:41 pm
Private answer

There are many examples of this throughout this forum but so far we don't have a post the asks for a generic solution that can be applied to a wide variety of solutions. So I have updated the question of your title to make this post stand out when folks are searching for this exact solution.

Rather than try to use your example I created my own solution. The example you provided didn't really make sense. Why? Because your variable named "data" is never going to be negative. It will always be positive. And it does not make sense to display the word "Negative" when close is less than 1.

In my example I have created a variable named "upBar" that checks if the close of the current bar is higher than or equal to the close of the previous bar. The AddLabel() statement then checks to see if the current bar is an up bar and prints the words "Up Bar" in the watchlist column. If its not an up bar the watchlist column will display the words "Down Bar".

The color of text is set to change from green to red to match the color of the bar on the chart.

def upBar = close >= close[1];
AddLabel(yes, if upBar then "Up Bar" else "Down Bar", if upBar then Color.GREEN else Color.RED);

And you can only have one AddLabel() statement in a custom watchlist column. And if you use an AddLabe() statement in a custom watchlist column you must NOT have any plot statements.

Let's see if any of our viewers can work out a solution that displays the following text options in the custom watchlist column:

"Outside Bar"

"Inside Bar"

"Doji Bar"

Technically speaking, a Doji bar may also be an inside bar or a an outside bar. So you must build the nested if/than/else statement to account for that. Good luck and have some fun!

Marked as spam
Posted by (Questions: 39, Answers: 3752)
Answered on October 23, 2021 2:46 pm
Thanks Pete This is exactly what is needed.
( at October 23, 2021 4:22 pm)