Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    I have number of type double. double a = 12.00 I have to make it as 12 by removing .00 Please help me


    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,
    Doing some calculations with doubles which then need to be cast to an int. So i have a quick question, when casting a double say 7.5 to an int, it will return 7. Is this a product of rounding or j...


    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 rocketman7, Today, 02:12 AM
        0 responses
        2 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        1 view
        0 likes
        Last Post dustydbayer  
        Started by inanazsocial, Today, 01:15 AM
        0 responses
        3 views
        0 likes
        Last Post inanazsocial  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Working...
        X