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.

    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?

        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.

            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 NullPointStrategies, Today, 05:17 AM
              0 responses
              52 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              130 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              70 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              43 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              48 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X