Round Up Zero digits after decimal

GPM

New member
I am new to this forum and also new to Think Or Swim. I did a search and could not find answers to my questions so trying a new post. Hope someone can help me.

1) In my watchlist, I am using there pre-built %Change column. It shows me percentage change in price since previous trading days' close. But I cannot find the prebuilt column names for "previous day close price" and "dollar change" since yesterday's close.

2) I want to create custom columns for "dollar change" and "%Change" and want to show rounded up values.. How do I round up so that my custom columns show zero digits after the decimal. Thus for example, if I have a number 123.45 I want to show it as 123, and if I have 12345.67 I want to show it as 12346. If zero digits is not possible, I can live with 123.0 (which seems to work when I say round (num, 0)

3) Same thing with PE ratio. Is there a way to refer to the pre-built watch list column called Price/Earnings Ratio when I am writing a custom think Script column?


thank you.
 

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

Hi,

I am looking for coding that given the following formula would stipulate that the remainder be a whole number:

xnumber / 5 = whole number remainder

For instance: 40/5 = 8 (meets criteria)
39/5 = 7.8 (does not meet criteria)

This I would use to stipulate a specific color for a specific price level.

Thanks for any help.

Bob
 
@generic

It was exactly what I was looking for. And thankyou for your offer. I am working to learn Thinkscript as I use it on my trading charts. Your code I used in this indicator:

https://usethinkscript.com/threads/auto-significant-price-levels-for-thinkorswim.4867/post-56809

It was used to identify and color price levels that are rounded to integers of 5, so they are clearly identifiable on the minute chart I trade for a specific stock. The interval (integer) might change based on the instrument, but the indicator gives me a way to specify the integer, (and thus price level) I am looking to emphasize.

Again, thanks. This was the last thing I needed in order finish the indicator and post.

Regards,
Bob
 
I am new to this forum and also new to Think Or Swim. I did a search and could not find answers to my questions so trying a new post. Hope someone can help me.

1) In my watchlist, I am using there pre-built %Change column. It shows me percentage change in price since previous trading days' close. But I cannot find the prebuilt column names for "previous day close price" and "dollar change" since yesterday's close.

2) I want to create custom columns for "dollar change" and "%Change" and want to show rounded up values.. How do I round up so that my custom columns show zero digits after the decimal. Thus for example, if I have a number 123.45 I want to show it as 123, and if I have 12345.67 I want to show it as 12346. If zero digits is not possible, I can live with 123.0 (which seems to work when I say round (num, 0)

3) Same thing with PE ratio. Is there a way to refer to the pre-built watch list column called Price/Earnings Ratio when I am writing a custom think Script column?


thank you.
Use this type of styling, this is an example for showing volume average of 10 days

def avgVol = Average(volume, 10);
AddLabel(yes, Round(avgVol, 0));
 
To piggyback off of this older conversation, I am trying to round price lines on my chart to the nearest tick value (for futures).

Right now I am using:
Code:
Round(value, ticksize());

The value seems to round to the nearest point, not tick.

Any suggestions?
 
To piggyback off of this older conversation, I am trying to round price lines on my chart to the nearest tick value (for futures).

Right now I am using:
Code:
Round(value, ticksize());

The value seems to round to the nearest point, not tick.

Any suggestions?

Here is one way

Capture.jpg
Ruby:
#Example_MovingAverage_Round_to_Ticksize
plot x = ExpAverage(close, 9);
#Normal rounding
AddLabel(1, Round(x), Color.YELLOW);
#Round to Ticksize
AddLabel(1, Round((x / TickSize()), 0) * TickSize(), Color.WHITE);
 
Hello Everyone
I am new at coding, I know enough to be very dangerous, My question is there a way to round up to the nearest whole number in the code like you can in Excel ?
 
For anyone who wants zero decimal places in your watchlist column, just replace your Plot with AddLabel and then utilize the Round function.
The downfall is the text appears white and can't be changed. It prevents me from using it on a column with dynamic background coloring.
EDIT- it also seems to mess up the sort, so not very useful.
 
Last edited:
For anyone who wants zero decimal places in your watchlist column, just replace your Plot with AddLabel and then utilize the Round function.
The downfall is the text appears white and can't be changed. It prevents me from using it on a column with dynamic background coloring.
EDIT- it also seems to mess up the sort, so not very useful.

sort text in a column
adding leading and trailing 0's so the text numbers sort correctly when addlabel() is used
https://usethinkscript.com/threads/...tion-from-addlabel-function.10456/#post-92584
post2

font color in a column
https://usethinkscript.com/threads/moving-average-crossovers-for-thinkorswim.229/page-6#post-64703
post103
 
Last edited:
WINNER from the above answers for Question #2 above on removing unnecessary decimal points:

Code:
AddLabel (yes, Round(MY_VAR, 0), color.WHITE);
(this rounded 49.95 to 49 in a table in MarketWatch).

You can also use Round(MY_VAR, 1) for one more digit, but unfortunately it doesn't add a ".0" if it rounds up to a zero.
The two and three digit scenarios are already covered by native ThinkScript functions.
 
I would like to only display 1 decimal in a label in a chart.

I'm using the label in a chart & setting the round to 1 this doesn't work as expected--2 decimals are always displayed no matter what rounding number I choose:
AddLabel (yes, Round(MY_VAR, 1), color.WHITE);

When I use AsText, two decimals are always displayed.

How do I round to 1 decimal place only? If that's not possible how do I truncate to 1 decimal place?

Thanks!
 
I would like to only display 1 decimal in a label in a chart.

I'm using the label in a chart & setting the round to 1 this doesn't work as expected--2 decimals are always displayed no matter what rounding number I choose:
AddLabel (yes, Round(MY_VAR, 1), color.WHITE);

When I use AsText, two decimals are always displayed.

How do I round to 1 decimal place only? If that's not possible how do I truncate to 1 decimal place?

Thanks!

your example code works fine when my_var = 4444/7

post your complete code, so others can see what you are really doing.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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