Sorting Custom Watch List Column

TOSUser21

New member
I have created the following Custom Watch List Column:

Code:
def capital = (volume*(close-close from 1 bars ago));
AddLabel(yes," " + AsDollars(capital));

The calculation works, but I am unable to sort the column in ascending or descending order. Do you know how I can edit this script so that I can sort the column accurately?

Thank you in advance for your help.
 

MerryDay

Well-known member
VIP
Well, technically it is sorting. But it sorting on the 1st number which isn't helpful. Anyway, I have seen this behavior when mixing volume and price in the same expression. I don't know of any way of overcoming this limitation in TOS. But I am not an expert. Perhaps someone will chime in with a way to convert it to an absolute value that would perhaps be sortable. At the moment you are SOL. sorry.
 

TOSUser21

New member
Well, technically it is sorting. But it sorting on the 1st number which isn't helpful. Anyway, I have seen this behavior when mixing volume and price in the same expression. I don't know of any way of overcoming this limitation in TOS. But I am not an expert. Perhaps someone will chime in with a way to convert it to an absolute value that would perhaps be sortable. At the moment you are SOL. sorry.
MerryDay—thank you for your follow-up reply. Hopefully, someone else may have a resolution. Take care!
 

rad14733

Well-known member
VIP
@TOSUser21 The problem you are encountering has to do with the fact that when using AddLabel() for a Custom WatchList Column all values are considered Strings... By switching to plot instead of AddLabel() you will eliminate this issue... The following code will work as expected but without the AsDollars() which can only be used with AddLabel() and AddChartBubble() to display numbers as Strings... You can't have it both ways... Forget about the dollar signs as they aren't required, nor should you be worried about how many minimum decimals points are displayed...

Ruby:
def capital = volume * (close - close[1]);
plot Data = Round(capital, 2);
 

TOSUser21

New member
rad14733--thank you very much for your feedback. I really appreciate your help. The code works and the sort is now accurate. Is there a way for commas to be inserted so that 1000.00 is displayed as 1,000.00? If not, then can three digits after the decimal point be displayed? That way I can put the result in thousands and then think of the decimal point as a comma so 1000.00 would be displayed as 1.000? Thank you again!
 

rad14733

Well-known member
VIP
@TOSUser21 I'm glad that works for you... No, we cannot add commas because that sends us back into the realm of being a string rather than a number... Numbers don't have commas or dollar signs, only strings do... And then we can't sort those strings like we can numbers... Settle for what works and don't sweat the fine details...

As for decimal points, you can change the 2 to 3 in the Round() function, or omit the function altogether and let the raw number be displayed...
 

TOSUser21

New member
rad14733--thank you for your additional feedback. I changed the Round function to 3, but it still only displays 2 digits. Your advice to not "sweat the fine details" is well received and I am now completely satisfied with the result. It will serve my purposes just fine.

Thanks again for all your help! Take good care!!
 

rad14733

Well-known member
VIP
@TOSUser21 Setting Round() to 3 only works as the maximum number of decimals... If the price has less than 3 decimal points it will only display as many as exist... Again, anything else in Thinkscript would force the number into a string... That's just one of many Thinkorswim quirks we have to live with...

Good luck...
 

Similar threads

Top