Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

object reference not set to an instance of an object

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

    object reference not set to an instance of an object

    Working on a strategy that was working fine. Made some changes and now it stops the 1st time it tries to place and order.

    I get the following error in the LOG

    object reference not set to an instance of an object

    Any ideas as to how I might find which object I am trying to reference that is not an instance of an object?

    I have tried to place print statements in the code to see how far it is getting before stopping. I have OnBarUpdate, OnOrderUpdate and OnExecution sections

    It looks like the orders are placed and I get all the way though OnOrderUpdate but do not begin OnExecution???

    #2
    I believe the log should show which method the object reference error occurs? If not, you can try wrapping your code in try/catch blocks to see where the exception is, the within this block of code, add some print statements to see which object you are accessing is null.

    For example:

    if (Instrument == null)
    Print("The exception is at instrument")

    etc...
    RayNinjaTrader Customer Service

    Comment


      #3
      The whole message reads
      Error on Calling "OnBarUpdate" method for Stategy "XXXX". Object Reference is not set to an instance of an object

      I am using two time periods. The second time period does not seem to be accessed. I have a print statement at the beginning but it does not print so I assume we stopped before getting to it.

      It is interesting that I am placing 2 seperate orders however it goes though the OnOrderUpdate method 4 times. I have print statements embedded in it and they show 4 times....

      Is there documentation on try-catch blocks?
      Last edited by clfield; 01-07-2010, 05:26 PM.

      Comment


        #4
        Do you try adding a series you're datafeed / broker would not support clfield?



        Please see this on checking for null references -



        And this on 'try and catch' to isolate out -

        Comment


          #5
          Thanks for the info. I did figure out how to add a try-catch block and did find the error that was stopping the strategy.
          I am still very much a novice at C#. I have checked several books, but I guess our use of c# in ninja is a realtively small section of the overall platform.
          Thanks for the links

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          152 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          87 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          131 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          127 views
          1 like
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          106 views
          0 likes
          Last Post CarlTrading  
          Working...
          X