Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on Converting Max or Min Statements

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

    Error on Converting Max or Min Statements

    Dear Support,

    There are many NT7 indicators that include a MAX or MIN statement. When converting these indicators to NT8 using the conversion tool on this forum the conversion will compile nicely. However, for some indicators, when the indicator is applied to a chart this error pops up and nothing happens.

    " Value of property "Period" of NinjaScript"MAX" is 0 and not in valid range between 1 and 2147483647."

    The attached converted Open Range Indicator is a simple example. There are already conditions to assure the value for "period" is not 0. The syntax for lines 137 and 140 is per documentation. Also, looking at trace and log file only the above error is repeated.

    Could you please perhaps comment or see what causes this error?

    Many Thanks.
    Attached Files

    #2
    Hello alligator, and thank you for your question.

    I have prepared a simplified, stripped down indicator which does not produce the message in question. It operates over the same time period as the MAX indicator you produced on line 137, and on the same data series. I would like to advise either refactoring your code to use a call similar to the call in the attached indicator, or adding your code to the attached indicator piece-by-piece until it works as desired. If any questions come up in your refactor process, please let us know and we will be happy to assist further.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JessicaP View Post
      Hello alligator, and thank you for your question.

      I have prepared a simplified, stripped down indicator which does not produce the message in question. It operates over the same time period as the MAX indicator you produced on line 137, and on the same data series. I would like to advise either refactoring your code to use a call similar to the call in the attached indicator, or adding your code to the attached indicator piece-by-piece until it works as desired. If any questions come up in your refactor process, please let us know and we will be happy to assist further.
      Thank You JessicaP,

      I followed your example and refactored the code as instructed. It does compile but as you can see I am still getting the same Error as noted above when applied to the chart and nothing happens.

      Than you.
      Attached Files

      Comment


        #4
        Thank you again, alligator.

        It looks like your MAX and MIN arguments are getting invalid values as their second argument. I am attaching a copy of your code with some trace information added, which will help us debug what is occurring. Could you send us the final output matching my additions to your code that occur either in your logs or your output window, after intentionally running your indicator again and forcing it to crash?
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JessicaP View Post
          Thank you again, alligator.

          It looks like your MAX and MIN arguments are getting invalid values as their second argument. I am attaching a copy of your code with some trace information added, which will help us debug what is occurring. Could you send us the final output matching my additions to your code that occur either in your logs or your output window, after intentionally running your indicator again and forcing it to crash?
          Many Thanks a bunch JessicaP,

          I run your modified version and here is what I get from trace file:

          " Indicator 'OpenRange': Error on calling 'OnBarUpdate' method on bar 1: Object reference not set to an instance of an object. "

          And here is what I get from output file:

          "startBarsAgo: 0
          endBarsAgo: 0
          Value of property 'Period' of NinjaScript 'MAX' is 0 and not in valid range between 1 and 2147483647.
          Indicator 'OpenRange': Error on calling 'OnBarUpdate' method on bar 1: Object reference not set to an instance of an object. "

          I can't see how the startBarsAgo and endBarsAgo have 0 value since both of these are clearly defined as non-zero parameters.

          Thank you again.
          Attached Files
          Last edited by aligator; 10-30-2016, 10:21 PM.

          Comment


            #6
            Thank you for this additional information alligator. I am glad we were able to determine why this is occurring. It looks like MAX and MIN are operating as specified, and are warning you that they are being passed in a zero value.

            As to why they are being passed in a zero value, it looks like the lines in the most recent code sample we will need to review are lines 95 through 97.

            It turns out that startBarsAgo and endBarsAgo can indeed be zero values. The documentation for GetBarIdxByTime, here,



            provides no guarantees against non-zero values. It is in fact expected that these can be zero, since zero is a valid BarsAgo index. It is very likely that the reason you are getting zero values, is because there are points during historical data processing where you are attempting to pass in DateTime objects for which there are no corresponding bars.

            You will therefore need to refactor your code. Since your code appears to be an attempt to retrieve values from 06:30 AM and 07:01 AM, I would like to recommend instead using the GetBar method documented here,



            We are happy to help in any other way we can.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JessicaP View Post
              Thank you for this additional information alligator. I am glad we were able to determine why this is occurring. It looks like MAX and MIN are operating as specified, and are warning you that they are being passed in a zero value.

              As to why they are being passed in a zero value, it looks like the lines in the most recent code sample we will need to review are lines 95 through 97.

              It turns out that startBarsAgo and endBarsAgo can indeed be zero values. The documentation for GetBarIdxByTime, here,



              provides no guarantees against non-zero values. It is in fact expected that these can be zero, since zero is a valid BarsAgo index. It is very likely that the reason you are getting zero values, is because there are points during historical data processing where you are attempting to pass in DateTime objects for which there are no corresponding bars.

              You will therefore need to refactor your code. Since your code appears to be an attempt to retrieve values from 06:30 AM and 07:01 AM, I would like to recommend instead using the GetBar method documented here,



              We are happy to help in any other way we can.
              JessicaP, Thanks again and appreciate your help.

              I followed your recommendation and used the GetBar method instead. I still get the same errors in trace file and output window when I apply it to a 5 minutes chart.

              Thanks a bunch and have a wonderful time.
              Attached Files

              Comment


                #8
                Hello alligator,

                Since we have determined NinjaTrader, NinjaScript, and C# are all working as designed and I was able to answer your questions about their functionality, we are reaching the limit of the scope of the service we may provide. There are some logical steps that seem to be missing, such as accounting for the period of time between 6:30 and 7:01 in the morning when your 7:01 bars are not available, and instances where bars are created before 6:30 in the morning, which I do not see any logic in your code to account for.

                I am a technical support expert. If you would like I can speak with one of my colleagues who is an expert on the community surrounding NinjaTrader, who can help put you in contact with a professional NinjaScript consultant.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you so much JessicaP. I was able to figure out the code.

                  Many thanks for your support.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by cre8able, Today, 03:20 PM
                  1 response
                  9 views
                  0 likes
                  Last Post cre8able  
                  Started by fiddich, Today, 05:25 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post fiddich
                  by fiddich
                   
                  Started by gemify, 11-11-2022, 11:52 AM
                  6 responses
                  804 views
                  2 likes
                  Last Post ultls
                  by ultls
                   
                  Started by ScottWalsh, Today, 04:52 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post ScottWalsh  
                  Started by ScottWalsh, Today, 04:29 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post ScottWalsh  
                  Working...
                  X