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 ageeholdings, Today, 07:43 AM
            0 responses
            7 views
            0 likes
            Last Post ageeholdings  
            Started by pibrew, Today, 06:37 AM
            0 responses
            4 views
            0 likes
            Last Post pibrew
            by pibrew
             
            Started by rbeckmann05, Yesterday, 06:48 PM
            1 response
            14 views
            0 likes
            Last Post bltdavid  
            Started by llanqui, Today, 03:53 AM
            0 responses
            6 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            12 views
            0 likes
            Last Post burtoninlondon  
            Working...
            X