round down/up

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #41400 quote
    tav
    Participant
    Junior

    How do you round down or up in prorealtime?

    #41415 quote
    robertogozzi
    Moderator
    Master

    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
    icharttop and Antus thanked this post
    #41420 quote
    robertogozzi
    Moderator
    Master

    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).

    Marius thanked this post
    #41425 quote
    tav
    Participant
    Junior

    perfect thank you!

    #41430 quote
    Nicolas
    Keymaster
    Master

    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.

    #118575 quote
    dupont_a
    Participant
    Junior

    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 🙂

    Sascha thanked this post
    #118576 quote
    Nicolas
    Keymaster
    Master

    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.

    #118579 quote
    dupont_a
    Participant
    Junior

    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

    #118596 quote
    Vonasi
    Moderator
    Master

    PS : Sorry for haven’t use  “insert PRT code” button

    I tidied it up ! )

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

round down/up


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
tav @tavaziva_madzinga Participant
Summary

This topic contains 8 replies,
has 5 voices, and was last updated by Vonasi
6 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/23/2017
Status: Active
Attachments: No files
Logo Logo
Loading...