tavParticipant
Junior
How do you round down or up in prorealtime?
ROUND() rounds numbers to the nearest whole number, the documentation is a bit poor, since it shows only the rounding of 9.60.
I tested this fake strategy (one buy instrution is necessary to be executed) with returns wit no addiotion, adding 0.9 and 0.4, both with positive and negative values, in case you want ALWAYS round to the greatest or to the smallest whole number:
// returns
// +0.0 +0.9 +0.4
//a = round(2.0 + 0.4) // 2 3 2
//b = round(2.4 + 0.4) // 2 3 3
//c = round(2.5 + 0.4) // 3 3 3
//d = round(2.6 + 0.4) // 3 3 3
//e = round(2.7 + 0.4) // 3 4 3
a = round(-2.0 + 0.4) // -2 -1 -2
b = round(-2.4 + 0.4) // -2 -2 -2
c = round(-2.5 + 0.4) // -3 -2 -2
d = round(-2.6 + 0.4) // -3 -2 -2
e = round(-2.7 + 0.4) // -3 -2 -2
GRAPH a AS "a"
GRAPH b AS "b"
GRAPH c AS "c"
GRAPH d AS "d"
GRAPH e AS "e"
buy 1 contract at market
So, it appears that to ALWAYS round a number to the nearest greatest whole number you have to add 0.4 (both for positive and negative numbers).
By following the link, you can find a nice little code snippet made by Pepsmile that floor and ceil a number to the nearest one.
Hello,
I know this topic is old but it could be helps users like me who was affected by that issue.
I would like to get only the integer without decimal, and without a round to superior integer when my value is above 0.5
So I’ve created this code to get only the integer.
n= decimal number
IF round(n) > n then // Round(n) should return 2 in case of n = 1.53. // if 2 > 1.53
n = n - 0.5 // We substract 0.5 to be in lower round decimal // 1.53-0.5 = 1.03
n = round(n) // We can make a round of the new n // round(1.03) = 1
ENDIF
Have fun 🙂
Thank you @dupont_a , however there are now 2 new instructions in Prorealtime v11: floor and ceil
In a future update, the ROUND instruction will also have the capability to handle digits, such as ROUND(close,2). I’m testing it and it works fine.
Thx Nicolas, I’m still on v10.3.
I’m glad to learn that PRT has solved that for new version 🙂
PS : Sorry for haven’t use “insert PRT code” button