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 geddyisodin, 04-25-2024, 05:20 AM
            8 responses
            61 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            4 responses
            3,288 views
            1 like
            Last Post jgualdronc  
            Started by Option Whisperer, Today, 09:55 AM
            0 responses
            5 views
            0 likes
            Last Post Option Whisperer  
            Started by halgo_boulder, 04-20-2024, 08:44 AM
            2 responses
            22 views
            0 likes
            Last Post halgo_boulder  
            Started by mishhh, 05-25-2010, 08:54 AM
            19 responses
            6,189 views
            0 likes
            Last Post rene69851  
            Working...
            X