Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object Reference not set to an instance of an Object. Bars == Null

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

    Object Reference not set to an instance of an Object. Bars == Null

    I am getting the Object Reference not set to an instance of an Object error if I use Bars.IsFirstBarOfSession. I don't understand how this is possible since I am doing a check to see if Bars == null just before the exeption gets thrown. Also, the exception is getting thrown many hundreds of bars into the script so obviously bars was not null at some point and then turned null? Take a look at this screenshot:

    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

    #2
    Hello swcooke, thanks for your post.

    There must be some aspect of your script that's causing this. When I run a contrived test IsFirstBarOfSession works for me. If you strip out code that is not needed to detect IsFirstBarOfSession does it return true or false in this instance?

    Comment


      #3
      Hi, swcooke.

      Try to check the State value when error happened.

      Probably, exception happened in another part of program and script start disposing, and that moment you may receive "null reference" error in any line, referring NT objects .
      Last edited by fx.practic; 03-27-2020, 12:29 AM.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        Where would State be listed? I don't see it here with the rest of the variables:
        World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

        Comment


          #5
          Hi swcooke, thanks for your reply.

          You can add this check to you your code to make sure the Bars object is not accessed before State.DataLoaded. If it's accessed at any time before that it can cause errors.

          Comment


            #6
            Chris,

            This is not happening until a few hundred bars in sometimes.I am way passed the State.Dataloaded State. I was trying to locate the State value in VS after the exception occurs. See post from user: fx.practic.

            Comment


              #7
              Hi swcooke, thanks for your patience.

              I am getting a State enum variable in "this" from the VS Autos:


              Is there any further inheritance being used in your script exceeding NinjaScript.Indicators.Indicator?

              Comment


                #8
                I meant just this:

                Just try to put State variable in watch window.

                I guess, it would be State.Finalized
                fx.practic
                NinjaTrader Ecosystem Vendor - fx.practic

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X