Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Disabled

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

    Strategy Disabled

    I got the message "Strategy: Error on Calling 'OnBarUpdate' method on bar 313: Object reference not set to an instance of an object" and then my strategy disabled.

    #2
    Hello samish18,

    The error you are seeing means an object that was being used was null when you tried to use it. From the error we can see the problem is happening in your OnBarUpdate code and based on the bar number it is likely code within a condition because it happened after 312 bars had processed.

    To get a better idea of what is happening you can add prints into your OnBarUpdate code so you can visually see how the logic is executing in the output window. When you hit the error the last print would be the last code that was successfully executed, the problematic code comes after that print. Once it is known what part of the code is having an error it would be easier to tell what may have been null.

    JesseNinjaTrader Customer Service

    Comment


      #3
      The only object I was using were the bars themselves.

      Comment


        #4
        Hello samish18,

        What was the specific line that you found that is having an error that related to the bars?
        JesseNinjaTrader Customer Service

        Comment


          #5
          I was testing out a very simple strategy which makes this error all the more worrying - the strategy simply went long if the previous bar closed higher than the open and vice versa

          Comment


            #6
            Hello samish18,

            That does not help to know why you got that error. Some types of code need error handling to be used correctly, that is not specific to NinjaScript but in general with the underlying language being used called C#.

            Have you added prints into the code to see which line of code has a an error? if not that is going to be the very first step at addressing this type of question. We would need to know what the specific code was that you used to know why that error was generated, very likely you are missing a condition to check if that object is not null before using it.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by samish18 View Post
              The only object I was using were the bars themselves.
              I think the best way to debug these issues is to use the debug in Visual Studios. It'll break in Visual Studios, once you attach it to NinjaTrader and run the strategy. https://ninjatrader.com/support/help..._debugging.htm

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by michelz, 02-18-2025, 08:30 AM
              18 responses
              370 views
              0 likes
              Last Post neveral0n3  
              Started by laketrader, 03-10-2025, 07:20 AM
              4 responses
              34 views
              0 likes
              Last Post laketrader  
              Started by owensd, 04-21-2024, 11:34 PM
              19 responses
              190 views
              0 likes
              Last Post Leeroy_Jenkins  
              Started by bokorb, 03-14-2025, 02:45 PM
              2 responses
              26 views
              0 likes
              Last Post bokorb
              by bokorb
               
              Started by Schools, 03-14-2025, 03:32 PM
              1 response
              26 views
              0 likes
              Last Post Schools
              by Schools
               
              Working...
              X