• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

looking for a function or command that would only use the integer part of a number.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    looking for a function or command that would only use the integer part of a number.





    people with nt,



    nt support is consistently excellent. i'm sure the experts with nt support won't have any problem solving this request.



    oks, here is the deal; i'm trying to translate a strategy from another trading platform to nt. the only issue i have had is that in some instances i need nt to use only the integer portion from a number that can be fractional.


    for example, period/2, would be an integer if period is an even number but fractional if period is an odd number.


    ¿what functions or commands exist in nt to keep only the integer portion of a number (that would mean rounding down no matter the value of the fractional part)?


    i have noticed the strategy builder sometimes uses something like converttoint.32, but i couldn't find any references to this command. ¿does it round up for values above .5 and round down for values below as is usual? i haven't been able to determine how this command works, therefore i decided to ask for support.



    very well, thanks, regards,



    rtw

    #2
    Originally posted by rtwave View Post
    ¿what functions or commands exist in nt to keep only the integer portion of a number (that would mean rounding down no matter the value of the fractional part)?
    Lots of choices.

    Btw, this is a basic C# programming question, nothing to do with NinjaTrader.

    For all things C# programming, StackOverFlow.com is your friend.
    https://stackoverflow.com/questions/...ber-in-c-sharp

    I would probably just use the typecast example.

    If your number is stored in a double variable, like this,
    Code:
    double num = 13.67832;
    then this code,
    Code:
    int newnum = (int)num;
    converts the double value of num to integer, completely dropping (not rounding, dropping) the decimal portion of num.

    Again, a nice explanation from StackOverFlow.com,
    https://stackoverflow.com/questions/...t-strip-digits

    How can you find these answers for yourself?

    Try googling with searches like,

    C# drop fraction
    C# typecast int to double
    Always prefix your google query with 'C#' and you'll get lots of terrific answers, usually at StackOverFlow.com.

    Comment


      #3
      Hello rtwave,

      Thanks for your post.

      Thanks to member bltdavid for the good suggestions and advise.

      You can find out about the ConvertTo here: https://docs.microsoft.com/en-us/dot...ramework-4.7.2

      Paul H.NinjaTrader Customer Service

      Comment


        #4



        thanks, bltdavid and Paul H.



        i continued to research into this matter and learned that the Convert.ToInt32 function is definitely not what i have been looking for. microsoft defines it as:


        Returns
        Int32

        value, rounded to the nearest 32-bit signed integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is converted to 4, and 5.5 is converted to 6.


        in the end, i just placed an (int) command before each instance where any calculation is done to the value for period and this worked perfectly, for example: (int)(Period / 2).



        thanks again, regards.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by dkbyond, Today, 04:11 PM
        0 responses
        5 views
        0 likes
        Last Post dkbyond
        by dkbyond
         
        Started by markus3500, Today, 03:29 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_EricB  
        Started by bohenriksen, Today, 04:00 AM
        1 response
        21 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by brett0, Today, 12:33 PM
        3 responses
        16 views
        0 likes
        Last Post marcus2300  
        Started by lordvader34, Today, 11:12 AM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Working...
        X