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

Rounding question

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

    Rounding question

    Hello,

    my script is:

    risk_long = GetCurrentBid() - Swing(5).SwingLow[0];
    psize_long1 = accbalNew * (riskf/100)/risk_long;
    psize_long2 = (psize_long1/1000);

    PTLongTA1 = psize_long2 *0.3;
    PTLongTA1 = Math.Round(PTLongTA1);

    PTLongTA2 = psize_long2 *0.3;
    PTLongTA2 = Math.Round(PTLongTA2);

    PTLongTA3 = psize_long2 *0.4;
    PTLongTA3 = Math.Round(PTLongTA3);

    I need integers, rounded up and rounded down.
    How can I implement it?

    #2
    Hello Blackburn,

    Thank you for your post.

    What values need to ints? What values are currently doubles?

    Comment


      #3
      actually all values are doubles.

      PTLongTA1 , PTLongTA2 and PTLongTA3 need to ints

      Comment


        #4
        Hello BlackBurn,

        Thank you for your response.

        You can use Math.Round(value, 0) and then Convert.ToInt32().

        Please visit the following links for more information:

        Comment


          #5
          Can I use "round.math" also für rounded down?

          Comment


            #6
            Originally posted by Blackburn View Post
            Can I use "round.math" also für rounded down?
            Use Math.Round() for mathematical rounding.
            Use Math.Ceiling() to force rounding up.
            Use Math.Floor() to force rounding down.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sgordet, Today, 05:24 AM
            0 responses
            2 views
            0 likes
            Last Post sgordet
            by sgordet
             
            Started by royhagerman, Today, 04:30 AM
            0 responses
            1 view
            0 likes
            Last Post royhagerman  
            Started by haas88, 03-21-2024, 02:22 AM
            18 responses
            208 views
            0 likes
            Last Post haas88
            by haas88
             
            Started by Board game geek, Today, 02:20 AM
            0 responses
            7 views
            0 likes
            Last Post Board game geek  
            Started by knighty6508, Today, 01:20 AM
            2 responses
            16 views
            0 likes
            Last Post knighty6508  
            Working...
            X