QuantNomad

Proper Round Functions [QuantNomad]

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.
Script de código aberto

No verdadeiro espírito TradingView, o autor deste script o publicou com código aberto, para que os traders possam compreendê-lo e verificá-lo. Um brinde ao autor! Você pode usá-lo gratuitamente, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa. Você pode favoritá-lo para utilizá-lo em um gráfico.

Quer usar esse script no gráfico?
Courses:
Pine Programming: https://qntly.com/pineprog
Advanc. Pine Use-Cases: https://qntly.com/advpine

Access to Pro Indic.: https://qntly.com/proind

YouTube: https://qntly.com/youtube
Discord: https://qntly.com/discord
Telegram: https://qntly.com/tel

Comentários

Thank you very much ! Very useful.
+1 Resposta
Thank you...thank you so much
Resposta
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.
Resposta
QuantNomad NorthStarDayTrading
@NorthStarDayTrading, Try something like: round(close / 0.25) * 0.25
Resposta
@QuantNomad, "round_to_mintick" is the answer. Wanted to share with you for future reference.
Resposta
thank you very much, much appreciated!!
Resposta
Awesome! Very Helpful!
Resposta
You're the man. Thnx
Resposta