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

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 NeoTraderBot, Today, 10:55 PM
              0 responses
              5 views
              0 likes
              Last Post NeoTraderBot  
              Started by OliverWaters, Today, 10:35 PM
              0 responses
              6 views
              0 likes
              Last Post OliverWaters  
              Started by Graci117, 07-06-2024, 09:32 AM
              6 responses
              37 views
              0 likes
              Last Post Graci117  
              Started by AdamDJ8, 07-01-2024, 06:50 PM
              2 responses
              120 views
              0 likes
              Last Post AdamDJ8
              by AdamDJ8
               
              Started by AdamDJ8, 07-01-2024, 05:55 PM
              3 responses
              32 views
              0 likes
              Last Post AdamDJ8
              by AdamDJ8
               
              Working...
              X