Color watchlist based on percent change from previous close


Category:
0
0

Hey all!

I need help creating specific background color for different tiers of percentages for my Watchlist column:

50% + = violet
30% – 50% = cyan
0% – 30% = light green
0% = black
Less than 0% = grey

Here’s the code I have so far …Thank you!!

def chng = round((close / close[1] -1),2);

addlabel(yes, asPercent(chng));

assignBackgroundColor(if chng > 0 then color.BLUE else if chng < 0 then  color.GrAY else color.CuRRENT);
RESOLVED
Marked as spam
Posted by (Questions: 3, Answers: 2)
Asked on March 28, 2020 4:34 pm
150 views
0
Private answer

Here you go:

def percentChange = Round(100 * (close / close[1] -1), 2);
AddLabel(yes, Concat(percentChange, "%"), Color.BLACK);
AssignBackgroundColor(if percentChange < 0 then Color.GRAY else if percentChange < 30.0 then Color.LIGHT_GREEN else if percentChange < 50.0 then Color.CYAN else Color.VIOLET);

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on March 29, 2020 9:49 am
0
Thank you!!
( at March 29, 2020 12:50 pm)