Sorting watchlist by percentage


Category:
0
0

Hello Pete,

Hope your doing well.

Do you know if it’s possible to properly sort a watchlist using the AsPercent() function (in a custom column)?

I have some code (shown below) that is used to calculate the relative daily volume of an instrument; however, when I try to sort this column, it does not sort properly – it seems to sort based on the first numercal value and not the value as a whole. I’ve tried different methods but have been unsuccessful thus far, any help you can provide is appreciated.

input offset = 1;
def rVol = volume(period = AggregationPeriod.DAY) / Average(volume(period = AggregationPeriod.DAY), 63) [offset];
AddLabel(yes, Round(rVol, 2), Color.BLACK);
AssignBackgroundColor(if rVol > 10 then Color.BLUE
else if rVol > 8 then Color.BLUE
else if rVol > 6 then Color.DARK_GREEN
else if rVol > 4 then Color.GRAY
else if rVol > 2 then Color.DARK_GRAY
else if rVol > 1 then Color.DARK_RED
else if rVol < 1 then Color.PLUM else Color.CURRENT);
AddLabel(yes, asPercent(rVol));

 

 

 

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 8, 2021 9:23 pm
285 views
1
Private answer

This is not a percent solution, but this is my workaround for having watchlist columns sort correctly:

AddLabel(yes, if rvol < 1 then "0" + asPercent(rVol) else asPercent(rVol));

Marked as spam
Posted by (Questions: 1, Answers: 1)
Answered on April 18, 2021 12:58 am
0
Thanks for providing your workaround for this. I have up-voted your solution so that is appears at the top of the previous answer I provided.
( at April 18, 2021 8:24 am)
0
Private answer

This is a known issue that has been discussed in the forum on numerous occasions. There is no way to work around this issue except to plot the numeric value instead of using the AddLabel() statement.

So this will sort correctly:

plot data = rVol;

But this will never sort correctly:

AddLabel(yes, asPercent(rVol));

Perhaps someday Thinkorswim developers will correct this issue. But unless someone tells them they will not be aware a problem exists.

 

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on April 9, 2021 10:18 am
0
Thanks Pete, much appreciated.
( at April 9, 2021 9:16 pm)