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


Market Replay and Instance of an Object Null Errors

  • Filter
  • Time
  • Show
Clear All
new posts

    Market Replay and Instance of an Object Null Errors

    Hi all!

    I'm running into an issue where some code I've been working on to display volumetric data is throwing up instance of an object errors in Market Replay. It's strange because the code seems to work just fine in a live trading environment, but not on a recorded one.

    Here's the specific code that's causing the problem:

    protected override void OnBarUpdate()
    if (Bars == null)
    // For our volumetric bars
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType
    = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    Print("=========================================== ==============================");
    Print("Bar: " + CurrentBar);
    [B]Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
    Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);[/B]
    Print("=========================================== ==============================");
    The two bolded lines above are what's causing the "Object reference not set to an instance of an object." error in Market Replay. How can I check to make sure they aren't null so it doesn't stop the strategy?

    I know it's probably something basic, but I'd rather check here than banging my head against the wall for another half hour.
    Thanks in advance for any advice or guidance! Feel free to send me off to a related URL to learn more if that's easier.

    Hello Spiderbird,

    Is barsType null?

    See the check for null in the code sample from the help guide.

    Do you have historical tick data downloaded for any days of historical data that is loading?
    Chelsea B.NinjaTrader Customer Service


      Hi NinjaTrader_ChelseaB ! Good to see you again.

      And yes, I was a dummy. I had neglected to put the following code to null barsType. Here's the updated code:

      // For our volumetric bars
      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType
      = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
      [B]if (barsType == null)
      if (IsFirstTickOfBar) // If this is the first tick of a new bar, start all this material
      That also means that my market recordings of the past didn't capture the proper data to show up in my output window. I thought I had, but maybe I didn't check something in the Market Data option window. I'll include a screenshot of what I have now.

      Click image for larger version

Name:	MarketPlayback_MarketData.png
Views:	67
Size:	28.5 KB
ID:	1192738

      Am I supposed to use Market Replay or Historical Data to show volumetric bar data in the output window? Historically I've always used the Market Replay option.

      Thanks again for your help!


        Hello Spiderbird,

        Historical tick data is necessary for this indicator to load historically.

        Market Replay data are recordings used for the Playback connection.

        What connection are you connected to?
        You may not need to record either of these.
        Chelsea B.NinjaTrader Customer Service


          Hi Chelsea!

          I'm using Market Replay data that I've recorded in previous sessions via NT/IB, utilizing the 'Playback Connection' within NT8. I'm pretty sure I have the option for recording ticks active, but I can record the market tomorrow and double check my settings.

          I can usually see all of the volumetric data from the NT guide example when I start the strategy in real time.

          For reference, I've usually recording market data to get the tick data I'm looking for in my charts. I'm normally using 20 tick charts to interact with the market.

          Are there other settings I should double check?



            The most popular futures and forex instruments are recorded on our market replay server and will usually have up to 90 days worth of data available.

            Note, this data can be played back, but does not load historically on a chart.

            If you broker is Interactive Brokers, then recording historical tick data would be necessary as historical tick data is not provided.
            Chelsea B.NinjaTrader Customer Service


              Hi Chelsea,

              Do you know if that market data provided by NinjaTrader includes DOM or tick data? If so, that would be amazing.
              And yes, I'm aware of IB's lack of recording tick data. I've been recording market sessions ever since I found that out.

              Good news is that I figured it out!

              It had nothing to do with the code per se. It was actually where the strategy was being started from. If you right click on the volumetric chart you want to use for your strategy... select and enable your strategy... it works like charm. That's both with live market data and market replay.

              However, if you start the strategy from the Control Center and just select the security, the connection to use and other related parameters, it won't print anything and has null defined for all barsType data. I would have thought by simply pointing the strategy to the security in the Control Center that it would work. But nope! You have to enable the strategy on the actual volumetric chart you want the strategy to run.

              So there you go. Problem solved!

              Thanks again for your time and attention NinjaTrader_ChelseaB !


                Hello Spiderbird,

                Downloaded Market Replay data from NinjaTrader's servers has Level 2 Depth of Market for futures.
                Chelsea B.NinjaTrader Customer Service


                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello Spiderbird,

                  Downloaded Market Replay data from NinjaTrader's servers has Level 2 Depth of Market for futures.
                  Very cool! I'll check it out tomorrow. Thanks again Chelsea.


                  Latest Posts


                  Topics Statistics Last Post
                  Started by ballston, 05-07-2021, 06:32 AM
                  12 responses
                  Last Post tjfintrade  
                  Started by Shai Samuel, Yesterday, 07:43 AM
                  2 responses
                  Last Post Shai Samuel  
                  Started by StealthM93, 03-10-2023, 04:09 PM
                  15 responses
                  Last Post StealthM93  
                  Started by Net_Trader, 03-15-2023, 03:17 PM
                  12 responses
                  Last Post Net_Trader  
                  Started by Uhumm, Today, 11:18 AM
                  1 response
                  Last Post Boomtheory