• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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
              Patrick H.NinjaTrader Customer Service

              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 Conall, Today, 06:11 AM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by CaptainAmericaXX, Today, 07:41 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Jim  
                Started by Longhornmark, Today, 07:06 AM
                2 responses
                7 views
                0 likes
                Last Post Longhornmark  
                Started by 2sureshk, Today, 07:29 AM
                0 responses
                5 views
                0 likes
                Last Post 2sureshk  
                Started by uday12, Yesterday, 10:26 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Working...
                X