Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why is instrument.MarketData.Bid sometimes null?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Why is instrument.MarketData.Bid sometimes null?

    Sometimes (not all the time) when accessing...

    instrument.MarketData.Bid or instrument.MarketData.Ask

    the object is null... is there a fix for this?

    TIA

    #2
    Hello defa0009,

    That is an internal property and is not designed to be used in NinjaScript to access bid data. If your strategy needs the bid price you can use the GetCurrentBid() method or add a secondary bid series or also OnMarketData bid events in realtime.


    Comment


      #3
      Thanks.. I'm doing this from an addon which is watching 10 instruments though?

      Comment


        #4
        Hello defa0009,

        In an addon you need to make a market data subscription and then use the market data event that you subscribed to, that is similar to OnMarketData. Just as a heads up for future addon questions please make sure to use the general development sub forum, in the strategy sub forum we would provide answers specific to strategies.

        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

        Comment


          #5
          Ok so if I subscribe that should be good enough? I shouldn't have to actually do anything in the OnMarketData event function?

          And I would access bid price via instrument.MarketData.Bid?

          I looked for an AddOn forum but didn't see one.

          Comment


            #6
            Hello defa0009,

            The correct way is shown in the sample, the instrument.MarketData.Bid is still an internal property not meant for use in NinjaScript. When you use an addon you are building a completely new tool which would require using the same approach as the internal tools, if you need data you need to make a data subscription and then use the MarketData events. If you follow the sample your code that uses the events like setting a variable or a UI value would go in here:

            private void OnMarketData(object sender, MarketDataEventArgs e)
            {
            // Do something with market data events
            }​

            Comment


              #7
              Ok so just this then...

              private void OnMarketData(object sender, MarketDataEventArgs e)
              {
              bid = e.Instrument.MarketData.Bid;
              }​​
              Last edited by defa0009; 04-30-2025, 09:07 AM.

              Comment


                #8
                Hello defa0009,

                Not quite, you still need to wait for the bid event, this is the same concept as using OnMarketData from an indicator or strategy.


                private void OnMarketData(object sender, MarketDataEventArgs e)
                {
                if(e.MarketDataType == MarketDataType.Bid)
                Print(e.MarketDataType + " " + e.Bid);
                }​

                Comment


                  #9
                  OK its working good now. Thanks

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  50 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  126 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  69 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  42 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X