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

Market Replay and Instance of an Object Null Errors

Collapse
X
 
  • 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:

    Code:
    protected override void OnBarUpdate()
    {
    
    if (Bars == null)
    return;
    
    
    // For our volumetric bars
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType
    = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    
    
    Print("=========================================== ==============================");
    Print("Bar: " + CurrentBar);
    Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
    Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
    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.

    #2
    Hello Spiderbird,

    Is barsType null?

    See the check for null in the code sample from the help guide.
    https://ninjatrader.com/support/help...tric_bars2.htm

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

    Comment


      #3
      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:

      Code:
      // For our volumetric bars
      
      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType
      = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
      
      if (barsType == null)
      return;
      
      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:	47
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!

      Comment


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

        Comment


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

          Comment


            #6
            Hello,

            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.
            https://ninjatrader.com/support/help...jaTraderServer

            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.
            https://ninjatrader.com/support/help...y_provider.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


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

              Comment


                #8
                Hello Spiderbird,

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

                Comment


                  #9
                  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.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by 309338, Today, 12:06 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post 309338
                  by 309338
                   
                  Started by AaronKoRn, Yesterday, 08:38 PM
                  2 responses
                  49 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by rocketstock, 08-05-2022, 09:36 PM
                  2 responses
                  73 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by ronyggg83, Yesterday, 03:48 PM
                  4 responses
                  49 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by preqc, 08-05-2022, 09:10 AM
                  1 response
                  34 views
                  0 likes
                  Last Post NinjaTrader_Jim  
                  Working...
                  X