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. 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:

    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

    #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:
        Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

        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:


              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:

                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 selu72, Today, 02:01 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by WHICKED, Today, 02:02 PM
                2 responses
                12 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by f.saeidi, Today, 12:14 PM
                8 responses
                21 views
                0 likes
                Last Post f.saeidi  
                Started by Mikey_, 03-23-2024, 05:59 PM
                3 responses
                51 views
                0 likes
                Last Post Sam2515
                by Sam2515
                 
                Started by Russ Moreland, Today, 12:54 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Erick  
                Working...
                X