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

Math.Round ?

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

    Math.Round ?

    In my code I have a list which I populate with,

    longLevels.Add(r3 -(Math.Max(2*TickSize,(r3-r2)*0.1)));

    I am trying to round the result to 2 dp before adding it, like this,

    longLevels.Add(r3 -(Math.Round(Math.Max(2*TickSize,(r3-r2)*0.1))),2);

    But im getting the error "No overload for method Add takes 2 arguments, but I am overloading the Math.Round with the second argument not the Add method??

    Where am I making my mistake?

    #2
    GKonheiser, the below should compile for you, there some issues in your brace placements :

    longLevels.Add(r3 -(Math.Round(Math.Max(2 * TickSize, (r3 - r2) * 0.1), 2)));
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for that.

      Is there a way to have all doubles rounded to 2 dp without explicitly coding each one?

      Comment


        #4
        Originally posted by GKonheiser View Post
        Thanks for that.

        Is there a way to have all doubles rounded to 2 dp without explicitly coding each one?
        Write a method, and call it as needed. If you put it into a partial class, you can call it for all your indicators.

        Comment


          #5
          Good idea, will think about it and give it a go. Would i write the method in with the strategy or separately, sorry if that's a stupid question.

          Comment


            #6
            Originally posted by GKonheiser View Post
            Good idea, will think about it and give it a go. Would i write the method in with the strategy or separately, sorry if that's a stupid question.
            If you write it in the strategy, it will belong only to the strategy (the presumption is that it would be a private method). If you try to make that a public method, then it can be called from another class if, and only if, your strategy is present in that installation of NT.

            OTOH, if you place it in a partial class, and expose it either as protected or public, then you can access it from other classes, (again as long as the partial class file is available, which, as you can make the method the only one in the class, means that there should be little objection to it being distributed).

            Comment


              #7
              Hello GKonheiser,

              Thank you for your response and thank you to Koganam for their assistance.

              As an alternative to what Koganam provided, you could use the UserDefinedMethods in NinjaTrader to set a method that you could call for any strategy or indicator: http://www.ninjatrader.com/support/h...ed_methods.htm

              Comment


                #8
                Originally posted by NinjaTrader_PatrickH View Post
                Hello GKonheiser,

                Thank you for your response and thank you to Koganam for their assistance.

                As an alternative to what Koganam provided, you could use the UserDefinedMethods in NinjaTrader to set a method that you could call for any strategy or indicator: http://www.ninjatrader.com/support/h...ed_methods.htm
                UserDefinedMethods is a partial class, with the unfortunate restriction that it cannot be exported, hence the suggestion to use a different, created file.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by kulwinder73, Today, 10:31 AM
                0 responses
                0 views
                0 likes
                Last Post kulwinder73  
                Started by terofs, Yesterday, 04:18 PM
                1 response
                22 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by CommonWhale, Today, 09:55 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Gerik, Today, 09:40 AM
                2 responses
                7 views
                0 likes
                Last Post Gerik
                by Gerik
                 
                Started by RookieTrader, Today, 09:37 AM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X