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);
    [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.

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

    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;
      
      [B]if (barsType == null)
      return;[/B]
      
      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:	184
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.


            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

            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 The_Sec, Today, 02:29 PM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  2 responses
                  30 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by Mindset, 05-06-2023, 09:03 PM
                  10 responses
                  265 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by michi08, 10-05-2018, 09:31 AM
                  5 responses
                  743 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by tsantospinto, 04-12-2024, 07:04 PM
                  4 responses
                  63 views
                  0 likes
                  Last Post aligator  
                  Working...
                  X