round down/up
Forums › ProRealTime English forum › ProOrder support › round down/up
- This topic has 8 replies, 5 voices, and was last updated 4 years ago by Vonasi.
-
-
07/23/2017 at 1:05 PM #4140007/23/2017 at 2:45 PM #41415
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:
12345678910111213141516171819202122// 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 3a = round(-2.0 + 0.4) // -2 -1 -2b = round(-2.4 + 0.4) // -2 -2 -2c = round(-2.5 + 0.4) // -3 -2 -2d = round(-2.6 + 0.4) // -3 -2 -2e = round(-2.7 + 0.4) // -3 -2 -2GRAPH a AS "a"GRAPH b AS "b"GRAPH c AS "c"GRAPH d AS "d"GRAPH e AS "e"buy 1 contract at market07/23/2017 at 2:54 PM #41420So, 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).
1 user thanked author for this post.
07/23/2017 at 3:02 PM #4142507/23/2017 at 4:29 PM #41430By following the link, you can find a nice little code snippet made by Pepsmile that floor and ceil a number to the nearest one.
02/03/2020 at 2:35 PM #118575Hello,
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.5So I’ve created this code to get only the integer.
123456n= decimal numberIF round(n) > n then // Round(n) should return 2 in case of n = 1.53. // if 2 > 1.53n = n - 0.5 // We substract 0.5 to be in lower round decimal // 1.53-0.5 = 1.03n = round(n) // We can make a round of the new n // round(1.03) = 1ENDIFHave fun 🙂
1 user thanked author for this post.
02/03/2020 at 2:44 PM #11857602/03/2020 at 2:59 PM #11857902/03/2020 at 5:52 PM #118596PS : Sorry for haven’t use “insert PRT code” button
I tidied it up ! )
-
AuthorPosts
Find exclusive trading pro-tools on