• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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:

    https://www.screencast.com/t/sLINz4TFgmy

    #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?

    Chris L.NinjaTrader Customer Service

    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:
        https://www.screencast.com/t/kpEZfieWPzj

        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.
          Chris L.NinjaTrader Customer Service

          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:
              https://clauber.tinytake.com/tt/NDE2NjUzMF8xMjg5ODU3Mw

              Is there any further inheritance being used in your script exceeding NinjaScript.Indicators.Indicator?
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                I meant just this:
                https://ninjatrader.com/support/help.../nt8/state.htm
                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 Fiocco, Today, 05:59 AM
                0 responses
                12 views
                0 likes
                Last Post Fiocco
                by Fiocco
                 
                Started by catinabag, Today, 06:09 AM
                0 responses
                6 views
                0 likes
                Last Post catinabag  
                Started by junposlee, Today, 02:59 PM
                0 responses
                1 view
                0 likes
                Last Post junposlee  
                Started by patpat, Yesterday, 11:02 AM
                2 responses
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by jameslee001, Yesterday, 08:09 AM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X