Issues showing % symbol and 2 decimal places in watchlist column

BrianP

New member
I have used the search throughout the web and this forum to find solutions. Guess I really don't understand things. Through search, I have found that I should use either AsPercent( ) or the +"%" in my code. I have tried inserting that in the codein many different places, but to no avail. The code (below) shows the correct results in the column but wish it would have a % symbol after each result. Also, the two decimal places work but if the last decimal is a zero, it only shows one ( EX: 11.50 shows up 11.5 ).
Here are the two different codes I'm working on:

FIRST
Code:
def high_52_week = highest(high, 252);
def percent_off = (close - high_52_week) / high_52_week * 100;

plot percent = percent_off;

SECOND
Code:
plot YTDPercentChange = round((((close - close(period = AggregationPeriod.YEAR)[1]) / close(period = AggregationPeriod.YEAR)[1]) * 100),2);

Any help much appreciated!
Gotta learn.
 
Solution
I have used the search throughout the web and this forum to find solutions. Guess I really don't understand things. Through search, I have found that I should use either AsPercent( ) or the +"%" in my code. I have tried inserting that in the codein many different places, but to no avail. The code (below) shows the correct results in the column but wish it would have a % symbol after each result. Also, the two decimal places work but if the last decimal is a zero, it only shows one ( EX: 11.50 shows up 11.5 ).
Here are the two different codes I'm working on:

FIRST
Code:
def high_52_week = highest(high, 252);
def percent_off = (close - high_52_week) / high_52_week * 100;

plot percent = percent_off;

SECOND
Code:
plot...
I have used the search throughout the web and this forum to find solutions. Guess I really don't understand things. Through search, I have found that I should use either AsPercent( ) or the +"%" in my code. I have tried inserting that in the codein many different places, but to no avail. The code (below) shows the correct results in the column but wish it would have a % symbol after each result. Also, the two decimal places work but if the last decimal is a zero, it only shows one ( EX: 11.50 shows up 11.5 ).
Here are the two different codes I'm working on:

FIRST
Code:
def high_52_week = highest(high, 252);
def percent_off = (close - high_52_week) / high_52_week * 100;

plot percent = percent_off;

SECOND
Code:
plot YTDPercentChange = round((((close - close(period = AggregationPeriod.YEAR)[1]) / close(period = AggregationPeriod.YEAR)[1]) * 100),2);

Any help much appreciated!
Gotta learn.

For First, set column agg to week, change def high_52_week and use addlabel() as follows:
Code:
def high_52_week = highest(high,52);
def percent_off = (close - high_52_week) / high_52_week * 100;

plot percent = percent_off;
addlabel(1,astext(-round(percent,2))+"%");

For Second, set column agg to year and use similar addlabel() code as follows:
Code:
plot YTDPercentChange = Round((((close - close(period = AggregationPeriod.YEAR)[1]) / close(period = AggregationPeriod.YEAR)[1]) * 100), 2);
AddLabel(1, AsText(-Round(YTDPercentChange, 2)) + "%");
 
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
842 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