TradingView
QuantNomad
Jun 28, 2020 9:10 AM

Proper Round Functions [QuantNomad] 

Bitcoin / U.S. dollarBitstamp

描述

Round function in PineScript is very simple and allows you to round numbers only to the closest integer number. This is a bit irritating because I very often have to round numbers to some decimal places and not integer.
So I created 2 functions I use all the time and now sharing them with you.

  • roundn - rounds the values in its first argument to the specified number of decimal places.
  • roundtick - rounds the values to current symbol mintick


I hope they will be useful for you.
评论
gorx1
Thanks for this one!!!
michaelobrien
How can I round the number of contracts bought and sold at each buy/sell point in my strategy. for example the strategy currently will buy 1.4575 contracts but I want it to buy 1.457 contracts or even 1.458 contracts, whereby the last number after the decimal place is rounded but I'm not too concerned about this.
Thank you
U88888
Thank you...thank you so much
Hachann
Thank you very much ! Very useful.
NorthStarDayTrading
How can we round to the nearest .25? For example, trading the ES, NQ and other Futures instruments, the tick size is 1.0, 1.25, 1.50, 1.75, 2.0. Thanks in advance.
QuantNomad
@NorthStarDayTrading, Try something like: round(close / 0.25) * 0.25
NorthStarDayTrading
@QuantNomad, "round_to_mintick" is the answer. Wanted to share with you for future reference.
tcwilliamson86
thank you very much, much appreciated!!
bh2358
Awesome! Very Helpful!
kurtsmock
You're the man. Thnx
更多