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.Max

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

    Math.Max

    Hello,


    I only find in forum and help guide how to get the max or min of 2 values. But this doesnt work when I want to get the max or min of eg 5 values like
    MaxN=Math.Max(value1, value2, value3, value4 value5);


    Where do I get the solution for this please? Where is this in the helpguide?


    Thank you!
    Tony

    #2
    Hello tonynt,

    Thanks for the post.

    The Max function will always take two args. You would nest them together to get the max of multiple numbers:

    Code:
    Math.Max(value1, Math.Max(value2, Math.Max(value3, (Math.Max(value4, value5)))));
    Please let me know if I may help further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello,


      thank you for your reply. OK, I wrote math.max. It can be another function, dont need to be the math.max. What if there are more values to check?


      Thank you!
      Tony

      Comment


        #4
        Hello Tony,

        Thanks for the reply.

        If you needed to take the maximum of multiple numbers in this way, then you would need to do some kind of recursive formula that takes a list. Do this at your own risk though, because recursive functions are not supported in NinjaScript. The supported way would be to evaluate them in a nest like in my previous post.

        Here is a publicly available example of a recursive max function that takes a list:


        Please let us know if we may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          a reply in this actual post concerning email to support: when replying to platformsupport there is the message "Undelivered Mail Returned to Sender". When sending a new email to [email protected] it is the same. No matter if attachment or not.

          Best
          Tony
          Last edited by tonynt; 07-27-2018, 12:13 AM. Reason: typing error

          Comment


            #6
            See here for information about "params" keyword.

            I typed up a quick method that should work (not tested).

            Code:
            public double MaxOf(double arg1, params double[] args)
            {
                double retval = arg1;
            
                foreach (double item in args)
                {
                    if (item > retval)
                        retval = item;
                }
            
                return retval;
            }
            Use it like this,

            Code:
            MaxN=MaxOf(value1, value2, value3, value4, value5);
            Last edited by bltdavid; 07-27-2018, 12:53 AM.

            Comment


              #7
              Hello tonynt,

              Thanks for the follow up.

              Can you send an email to us with your regular email and not through Help>Email support? If you can, restart your PC and test NinjaTrader's mail service again. You might need to test it on a different PC or a different network if possible. You might want to test to see if that happens with NinjaTrader 8 as well.

              Please let me know if I may be of any further assistance.
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by TraderBCL, Today, 04:38 AM
              2 responses
              7 views
              0 likes
              Last Post TraderBCL  
              Started by martin70, 03-24-2023, 04:58 AM
              14 responses
              105 views
              0 likes
              Last Post martin70  
              Started by Radano, 06-10-2021, 01:40 AM
              19 responses
              606 views
              0 likes
              Last Post Radano
              by Radano
               
              Started by KenneGaray, Today, 03:48 AM
              0 responses
              4 views
              0 likes
              Last Post KenneGaray  
              Started by thanajo, 05-04-2021, 02:11 AM
              4 responses
              471 views
              0 likes
              Last Post tradingnasdaqprueba  
              Working...
              X