Imitate %change watchlist column but with color

j0hnblake

New member
I'm unable to get this formula working quite the way I want. Surely there is no need for sacrifice and there is knowledge and betterment to be gained here.

I'm trying to create a watchlist column for the top% gainers on the day. With the column being sortable in ascending/descending as percent gained, displaying as lets say 63% with no decimal (not as 63.0%) the percent sign at the end (not in the beginning like %63) , and the text in color in green, yellow, or red.

Basically trying to imitate the default built in mark% change or change % column but with custom colors but I keep running into problems.

If I remove the percent from the end [AddLabel(yes, z + "%");] it works and the column is sortable but there is a decimal and .0 at the end displays as 63.0 in color.

If I add the percent at the end, the numbers displays like I want displays as 63% but I lose the color and ability to sort the column (it will just sort randomly not ascending/descending) if I put the percent sign before as %63 i can't add color.

Surely, there is a way,



Here is what I am working with

def AP = AggregationPeriod.DAY;
def y = close(period = AP)[1];
def x = Round(100*((close/y)-1),0);
plot z=x;
z.assignValueColor(if z >= 100 then Color.GREEN else if z >= 50 and z < 100 then Color.YELLOW else if z >= 10 and z < 50 then Color.ORANGE else Color.RED);
AddLabel(yes, z + "%");
 
Solution
Interesting. I am also new to this stuff and was working on something similar.

Using addlabel changes the output to a string, which I had found unsortable. However, if you put the percent symbol in front and round, then the list seems sortable in this limited instance.

I changed the code to get your colors back. I assume you can't use assignvaluecolor on a text string, so putting the color inside of addlabel works.

Percent in front is a bit wonky, but I think that is the best you might be able to hope for.

As an aside, now there is a new problem. Today IPDN had a 1022% gain, which got rounded to %12 by your code. It seems to work with anything under 1000%.

As a practical matter, it probably is a non-issue. I personally...
Interesting. I am also new to this stuff and was working on something similar.

Using addlabel changes the output to a string, which I had found unsortable. However, if you put the percent symbol in front and round, then the list seems sortable in this limited instance.

I changed the code to get your colors back. I assume you can't use assignvaluecolor on a text string, so putting the color inside of addlabel works.

Percent in front is a bit wonky, but I think that is the best you might be able to hope for.

As an aside, now there is a new problem. Today IPDN had a 1022% gain, which got rounded to %12 by your code. It seems to work with anything under 1000%.

As a practical matter, it probably is a non-issue. I personally wouldn't be buying into a stock with gains like that and if I already held it, I'd not be too worried about where the percent was.

Anyway, your code:

def AP = AggregationPeriod.DAY;
def y = close(period = AP)[1];
def x = Round(100*((close/y)-1),0);
plot z=x;
AddLabel(yes, "%" + z, (if z>=100 then Color.GREEN else if z >= 50 and z < 100 then Color.Yellow else if z>=10 and z <50 then Color.ORANGE else Color.RED));
 
Solution

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

I'm unable to get this formula working quite the way I want. Surely there is no need for sacrifice and there is knowledge and betterment to be gained here.

I'm trying to create a watchlist column for the top% gainers on the day. With the column being sortable in ascending/descending as percent gained, displaying as lets say 63% with no decimal (not as 63.0%) the percent sign at the end (not in the beginning like %63) , and the text in color in green, yellow, or red.

Basically trying to imitate the default built in mark% change or change % column but with custom colors but I keep running into problems.

If I remove the percent from the end [AddLabel(yes, z + "%");] it works and the column is sortable but there is a decimal and .0 at the end displays as 63.0 in color.

If I add the percent at the end, the numbers displays like I want displays as 63% but I lose the color and ability to sort the column (it will just sort randomly not ascending/descending) if I put the percent sign before as %63 i can't add color.

Surely, there is a way,



Here is what I am working with

def AP = AggregationPeriod.DAY;
def y = close(period = AP)[1];
def x = Round(100*((close/y)-1),0);
plot z=x;
z.assignValueColor(if z >= 100 then Color.GREEN else if z >= 50 and z < 100 then Color.YELLOW else if z >= 10 and z < 50 then Color.ORANGE else Color.RED);
AddLabel(yes, z + "%");
why are you using 2 output functions when only 1 is needed?
if you want to display a number and a %, then use addlabel.
if you want just a number, use plot.

text is sorted left to right.
so for text to 'sort correctly', all outputs need to be the same length. you need to add zeros to small numbers.

https://usethinkscript.com/threads/help-with-sorting-column-by-highest-value.13285/#post-111914
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
478 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