Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MAX of an indicator

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

    MAX of an indicator

    Hello,

    I'm having trouble with the syntax for obtaining the MAX value of an indicator over a period.

    As in, max value of the 50 period ATR over the last 10 bars.

    Any help appreciated!

    Thanks

    #2
    Hello MisterGee,
    You can use
    Code:
    MAX(ATR(50), 10);
    Hope it helps!

    Comment


      #3
      Thank you!

      Comment


        #4
        Finally got around to trying this out.

        Does not work, compiling gives code CS0029 "Cannot implicitly convert type 'NinjaTrader.Ninjascript.Indicators.MAX to'double'"

        I tried
        Code:
        MAX(ATR(50)[0], 10);
        and it doesn't like that either.

        Any other ideas out there?

        Comment


          #5
          May I know what exactly you want to do with this, if you can provide a snippet of your code I would be in a better position to help. MAX() is a series & if you need double then you must use MAX()[]. Example : MAX(ATR(50), 10)]0]

          Comment


            #6
            I can give you an example snippet:

            Code:
            int barsSinceEntry = //calculation for bars since entry
            double ATRFactor = MAX(ATR(50), barsSinceEntry)[0];
            basically want to find the max value of the ATR since entering a trade. Just tried adding [0] to the end and it threw an error that it was (0) and not within the required integer set.

            Comment


              #7
              This is because you're not defining barsSinceEntry, so its default value is considered as 0 & for MAX you need at least 1 period to calculate.

              Comment


                #8
                Try to have a fixed period value & see if it works, then you can do the calculation for barsSinceEntry, print its value to cross verify & then use it in MAX. In case your calculation gives 0 value to barsSinceEntry you need to have exception handling for MAX as it can't accept 0 period.

                Comment


                  #9
                  I have defined barsSinceEntry in my code. It works perfectly in all other instances, just don't care to take the time to write out all the extra. Just know that that variable is defined and working and should never result in a zero value

                  Comment


                    #10
                    Here you get an example to show it working.
                    SampleATRmax.zip

                    Comment


                      #11
                      My syntax is practically the same. Doesn't work when used in conjunction with a trading strategy. Compiles fine but doesn't work when trading.

                      Comment


                        #12
                        Are you getting any errors in control center log tab, also you can print the values to confirm.

                        Comment


                          #13
                          The only error I saw was a pop up error stating the value was 0 and can't be. I didn't check the log tab but I can later tonight when I am back at my screen.

                          Is there any NT Staff that can weigh in as well?

                          Comment


                            #14
                            OK, let me give you a trick till someone from NT responds.
                            Try this:
                            Code:
                            double ATRFactor = MAX(ATR(50), barsSinceEntry < 1 ? 1 : barsSinceEntry)[0];

                            Comment


                              #15
                              Hello MisterGee,

                              Thanks for your post.

                              As forum member s.kinra suggested, I would agree that using a print statement is needed to understand why the code is not working as expected. Is it possible that you do not have the first entry when the error occurs?

                              In post #14, forum member s.kinra is proposing a workaround to check to see if you integer variable bar since entry is less than 1 to set the value to be 1 or the actual value if 1 or greater.


                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              576 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X