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 Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,769 views
          0 likes
          Last Post Leafcutter  
          Started by Rapine Heihei, 04-23-2024, 07:51 PM
          2 responses
          30 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          943 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          10 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          7 views
          0 likes
          Last Post rocketman7  
          Working...
          X