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

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 -

        BertrandNinjaTrader Customer Service

        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 DanielTynera, Today, 01:14 AM
          0 responses
          2 views
          0 likes
          Last Post DanielTynera  
          Started by yertle, 04-18-2024, 08:38 AM
          9 responses
          40 views
          0 likes
          Last Post yertle
          by yertle
           
          Started by techgetgame, Yesterday, 11:42 PM
          0 responses
          12 views
          0 likes
          Last Post techgetgame  
          Started by sephichapdson, Yesterday, 11:36 PM
          0 responses
          2 views
          0 likes
          Last Post sephichapdson  
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,615 views
          0 likes
          Last Post aligator  
          Working...
          X