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 judysamnt7, 03-13-2023, 09:11 AM
                4 responses
                57 views
                0 likes
                Last Post DynamicTest  
                Started by ScottWalsh, Today, 06:52 PM
                4 responses
                36 views
                0 likes
                Last Post ScottWalsh  
                Started by olisav57, Today, 07:39 PM
                0 responses
                7 views
                0 likes
                Last Post olisav57  
                Started by trilliantrader, Today, 03:01 PM
                2 responses
                19 views
                0 likes
                Last Post helpwanted  
                Started by cre8able, Today, 07:24 PM
                0 responses
                9 views
                0 likes
                Last Post cre8able  
                Working...
                X