AssignValue Color to Watchlist Data

R

Rider

New member
I have the following script for a watch list column. My problem is when VolPctChg values are between 0% and -49% they display a red rather than yellow color. Iam trying to have values above zero display green and values between 0 and -50% display yellow and values below -50% display red. I would appreciate any help. Thanks.

Input length = 21;
Def vol = volume;
Def volAvg = Average(volume, length);
def volPctChg = 100 * ( vol - volAvg ) / volAvg;
plot VolumePercentChange = Round( volPctChg, 0 );

VolumePercentChange.AssignValueColor(if Volpctchg >.01 then color.GREEN else color.Yellow);

VolumePercentChange.AssignValueColor (if Volpctchg <-.50 then color.red else color.yellow);
 
rad14733

rad14733

Well-known member
VIP
You need to put the comparison logic all in one assignment command...
Code:
VolumePercentChange.AssignValueColor(if Volpctchg >.01 then color.GREEN else if Volpctchg <-.50 then color.red else color.yellow );
 
R

Rider

New member
Thank you for your response. I copied the script you provided and all the negative percentages are red in color. Even the -25% value is red.
 
P

Pensar

Active member
VIP
@Rider Try changing the values you provided to > 0 and < -50 instead of the decimals.
 
R

Rider

New member
Thanks Pensar! I made the change you recommended and it works! Thank you.
 
rad14733

rad14733

Well-known member
VIP
This line of code is why my fix didn't work... No real need to multiply by 100...
Code:
 def volPctChg = 100 * ( vol - volAvg ) / volAvg;
 

Similar threads

Top