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

on bar 0: Object reference not set to an instance of an object.

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

    on bar 0: Object reference not set to an instance of an object.

    If the first line in OnBarUpdate() is if (CurrentBar < 10) return;

    then why would I get a log error
    Error on calling the 'OnBarUpdate' method for indicator on bar 0: Object reference not set to an instance of an object.

    #2
    Hello,

    This is a special case and I do not recall the solution at this time. It has something to do with the lack of price data or corrupt price data. Try deleting your historical data and restarting NT then reconnecting. If that doesn't work, please reply and I'll have someone look into it further. Also, make sure you are on a instrument that has data via your provider. Of course, remove all other code to test the current bar check.
    DenNinjaTrader Customer Service

    Comment


      #3
      I have tried repairing the database. However deleting the historical data?? Without the data, there's no point.

      I have 7 months of historical tick data on a a handful of markets, collected slowly and painfully on NT 6.5 from Zen-fire. The problem shows on multiple instruments.

      Can a single instrument's historical data be deleted without harming the others? Or can you replace the 7 months of data after it is deleted?

      The bar check is definitely working. I basically changed the content to only do print statements and they start at the correct bar number. But I still get the error in the log.

      If you could find the previous case notes and solution, it would b appreciated.

      Comment


        #4
        Hello,

        I will have someone reply to you on Monday. Thank you for your patience.
        DenNinjaTrader Customer Service

        Comment


          #5
          I know you said some-one would contact me on Monday, and that is fine.
          When I saw this, I wanted to post the picture -- it should NOT behave this way.

          CB is a dumb little indicator that plots the CurrentBar so it would show in the Data Box.
          The stats simply prints a message to the output window on every bar except the first 500.

          Code:
          protected override void OnBarUpdate()
          {
               if (Bars == null || CurrentBar < 500) return;
               msg =  "Statistics Total Bars = " + Bars.Count; 
               msg += " & Current Bar = " + CurrentBar + " :  Price = " + Close[0]  ;
               Print(Time[0] + " : " + msg);
          }
          Attached Files

          Comment


            #6
            Lost Trader, the bottom of the picture is cut off, so I can't say for sure whether or not that could be the 500th bar. On NinjaTrader charts, CurrentBar = 0 for left-most bar when scrolled the whole way left. It is simply the first bar on the chart.

            This error does not necessarily indicate something wrong with your price data-it occurs when you try to access an object that might not exist or hasn't been initialized properly yet.

            To isolate exactly which line of code is causing the error, please sprinkle in Print() statements every few lines to start, and then when you've narrowed it down, place the Print()'s every other line to figure out exactly where the error is.

            The message you've received is a broad error, so to catch exactly what is going on, you can wrap the entire code in a try catch block like this:
            Code:
            OnBarUpdate()
            {
               try
               {
                  // all your code here
               }
               catch (Exception ex)
               {
                  Print(ex.ToString());
               }
            }
            AustinNinjaTrader Customer Service

            Comment


              #7
              Austin, I'll add the catch block, however...

              That chart picture IS scrolled all the way to the left. The Data Box shows that the cursor is on the very first bar == 0. I did not realize the scroll bar was necessary to reiterate that fact.

              The code should not be executing any print statement on bar 0 because of the very first code statement
              " if (Bars == null || CurrentBar < 500) return; "
              and yet it is...

              Why?

              Comment


                #8
                LT, sorry I didn't realize what I was looking at in the picture the first time around. The scroll bar is not necessary in this case.

                As for the early Print() statements, are you re-compiling and then re-loading the indicator on the chart?

                I ran your script and the output started at bar 500:
                Code:
                7/8/2010 8:01:00 AM : Statistics Total Bars = 1335 & Current Bar = 500 :  Price = 0.8695
                7/8/2010 8:02:00 AM : Statistics Total Bars = 1335 & Current Bar = 501 :  Price = 0.8691
                7/8/2010 8:03:00 AM : Statistics Total Bars = 1335 & Current Bar = 502 :  Price = 0.8692
                7/8/2010 8:04:00 AM : Statistics Total Bars = 1335 & Current Bar = 503 :  Price = 0.8689
                7/8/2010 8:05:00 AM : Statistics Total Bars = 1335 & Current Bar = 504 :  Price = 0.8688
                7/8/2010 8:06:00 AM : Statistics Total Bars = 1335 & Current Bar = 505 :  Price = 0.8684
                7/8/2010 8:07:00 AM : Statistics Total Bars = 1335 & Current Bar = 506 :  Price = 0.8683
                7/8/2010 8:08:00 AM : Statistics Total Bars = 1335 & Current Bar = 507 :  Price = 0.8683
                7/8/2010 8:09:00 AM : Statistics Total Bars = 1335 & Current Bar = 508 :  Price = 0.8686
                7/8/2010 8:10:00 AM : Statistics Total Bars = 1335 & Current Bar = 509 :  Price = 0.8687
                7/8/2010 8:11:00 AM : Statistics Total Bars = 1335 & Current Bar = 510 :  Price = 0.8685
                7/8/2010 8:12:00 AM : Statistics Total Bars = 1335 & Current Bar = 511 :  Price = 0.8688
                7/8/2010 8:13:00 AM : Statistics Total Bars = 1335 & Current Bar = 512 :  Price = 0.8693
                7/8/2010 8:14:00 AM : Statistics Total Bars = 1335 & Current Bar = 513 :  Price = 0.8692
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Austin,
                  In analyzing this again this morning, I discovered that some indicators were left in the Print statement (scrolled off the right of the screen). I spent some time narrowing down which produced an error. Unfortunately, there are two culprits, both 3rd party indicators. BTW the catch try block suggested below did NOT trigger the catch print statement, but an error is printed to the Control Panel log.

                  Why would simply calling an indicator (which plots on chart & displays in Data Box w/o problem) produce this log error? Why would (How could) it cause data to be collected/printed from the wrong bar?

                  Ben said there was a solution. What was the previous solution that worked?
                  I need more information to convince the 3rd party to admit they should fix it.
                  Thanks!

                  Comment


                    #10
                    Lost Trader, there are many, many reasons why simply calling an indicator could produce that error, like trying to set a DataSeries without initializing it, or accessing an object that is null.

                    Without seeing the code, I can't speculate on why it would produce that log error, nor would I know how or why that code would get data from the wrong bar.

                    Unfortunately we can't provide support for errors from 3rd party indicators. You would have to talk to them for a fix.

                    Ben wasn't quite correct because the error doesn't always stem from price data issues.

                    Please try it again with ZERO scripts loaded on the chart other than your CurrentBar script. If the error is from another script, it will occur whether or not your script is 100% correct and error-free.

                    If the error was in your script, it would've appeared in the try catch block:
                    Code:
                    try
                    {
                      Print("in try block");
                    
                      if (Bars == null || CurrentBar < 500) return;
                         msg =  "Statistics Total Bars = " + Bars.Count; 
                         msg += " & Current Bar = " + CurrentBar + " :  Price = " + Close[0]  ;
                         Print(Time[0] + " : " + msg);
                    }
                    catch (Exception ex)
                    {
                      Print("in the catch block");
                      Print(ex.ToString());
                    }
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Austin, once I pulled or commented out the 3rd party indicators, there was no error.

                      If I understand your comment, because the try catch block did not print an exception, the error is not in MY script but in theirs. Somehow their error changes the behavior of a print statement and time stamp in my script.

                      Comment


                        #12
                        Lost Trader, that would be correct, although I'm not sure how their scripts changed the output from yours. We would need all three scripts to test that out. The 3rd party stuff you are/were using isn't free is it? If so, could you provide a link?
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          Nope, not free. Is there a trick to referencing an indicator that's in a DLL vs a typical one that's in the Indicator folder?
                          I've sent a note to one of the company guys who has written something similar using their package on Tradestation -- we'll see what the response is.

                          Comment


                            #14
                            Lost Trader, there should be no difference to referencing an indicator in a DLL vs .cs.
                            AustinNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by jclose, Today, 09:37 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post jclose
                            by jclose
                             
                            Started by WeyldFalcon, 08-07-2020, 06:13 AM
                            10 responses
                            1,414 views
                            0 likes
                            Last Post Traderontheroad  
                            Started by firefoxforum12, Today, 08:53 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post firefoxforum12  
                            Started by stafe, Today, 08:34 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post stafe
                            by stafe
                             
                            Started by sastrades, 01-31-2024, 10:19 PM
                            11 responses
                            169 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X