Help with sorting column by highest value

PT_Scalper

Member
VIP
Hi all,

I'm in need of a bit of help trying to sort a column that always seems to be sorting from 9 down to 1.

How do I sort something by the highest value and not first digit of the number? This is on my WatchList as a customer column;

plot x = round((count),2);
x.assignValueColor (color.black);
assignBackgroundColor (if Count > 24 then Color.dark_green else if count > 20 then color.green else if count > 16 then color.yellow else if count > 12 then color.orange else if count > 8 then Color.red else color.dark_red);

AddLabel(yes, count, (if Count > 24 then Color.white else if count > 20 then color.black else if count > 16 then color.black else if count > 12 then color.black else if count > 8 then Color.black else color.black));

Thanks in advance.
 
Solution
I'm in need of a bit of help trying to sort a column that always seems to be sorting from 9 down to 1.

How do I sort something by the highest value and not first digit of the number? This is on my WatchList as a customer column;

you have 2 output functions ( plot , addlabel) trying to send data to 1 place.
1 will override the other. looks like the last one, addlabel is sending data to the cell.

the data is sorted as text , left to right. so without leading zeros, text wont sort as numbers.

option 1
remove addlabel, and it works.
shows numbers with 1 decimal place


option 2
remove the plot and change the addlabel to add a 0 if 'count' < 10


Code:
# zsortq1

#Help with sorting column by highest value
# Thread...
I'm in need of a bit of help trying to sort a column that always seems to be sorting from 9 down to 1.

How do I sort something by the highest value and not first digit of the number? This is on my WatchList as a customer column;

you have 2 output functions ( plot , addlabel) trying to send data to 1 place.
1 will override the other. looks like the last one, addlabel is sending data to the cell.

the data is sorted as text , left to right. so without leading zeros, text wont sort as numbers.

option 1
remove addlabel, and it works.
shows numbers with 1 decimal place


option 2
remove the plot and change the addlabel to add a 0 if 'count' < 10


Code:
# zsortq1

#Help with sorting column by highest value
# Thread starterPT_Scalper  Start date54 minutes ago

#I'm in need of a bit of help trying to sort a column that always seems to be sorting from 9 down to 1.

#How do I sort something by the highest value and not first digit of the number? This is on my WatchList as a customer column;


# qty of colors
def qty = 30;
# create random numbers, 1 to 10
def count = round((random() * qty) + 1, 0);


# works ,  show xx.x  number
#plot x = round((count),2);
#x.assignValueColor (color.black);



assignBackgroundColor (if Count > 24 then Color.dark_green else if count > 20 then color.green else if count > 16 then color.yellow else if count > 12 then color.orange else if count > 8 then Color.red else color.dark_red);


# text , doesnt have leading zeros,  does not sort like numbers
#AddLabel(yes, count, (if Count > 24 then Color.white else if count > 20 then color.black else if count > 16 then color.black else if count > 12 then color.black else if count > 8 then Color.black else color.black));



# text , sorts like numbers, has leading zeros
# color is the font color
addLabel(yes,
# (if count > 0 then "+" else if count < 0 then "-" else ",") +
 (if absvalue(count) < 10 then "0" else "") +
 absvalue(count)
# +
# (if int then ".0" else "")
, (if Count > 24 then Color.white else color.black));
#



another example of padding text in addlabel so data sorts like numbers
https://usethinkscript.com/threads/...tion-from-addlabel-function.10456/#post-92584

...
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
334 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top