Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

onBarUpdate vs onMarketData

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

    onBarUpdate vs onMarketData

    Hello,

    I was just wondering, if I need to assess bid/ask + trade information simultaneously, which would be more effective/accurate way to do that - onBarUpdate or onMarketData. What's the difference between two in described situation? In onMarketData I do, for example, e.Marketdata.Bid.Price, in onBarUpdate - GetCurrentBid().

    Thank you.

    #2
    danilam, you would need to be aware of the timing difference between the two, the OnBarUpdate() fires on each bar update or tick (COBC setting for study), while the OnMarketData() fires on each Level 1 event change (bid, ask, last ...).

    Easiest would be adding prints to your methods to see exactly when one vs the other is called for your scenario.

    Comment


      #3
      Thank you, Bertrand,
      In my case I need to get info only on trades, so even if I use onMarketData i always check:
      if (e.MarketDataType == MarketDataType.Last)
      So, presumably it would be enough for me to use onBarUpdate, since I can access last tick price as Close[0] and take bid/ask by GetCurrentBid/Ask.

      But, the question is if there's any advantages to use onMarketData instead. I understand that onMarketData will fire more often and evaluating if (e.MarketDataType == MarketDataType.Last) is probably not the most effective thing to do. So should I continue doing it?

      OK, suppose the trade just happened. Which method will fire first of these 2? (As they should fire both simultaneously, I suppose)

      Are GetCurrentBid called from onBarUpdate and e.MarketDataType.Bid.Price from onMarketData the same accurate by time?

      And one more unexpected question: you're saying "OnBarUpdate() fires on each bar update ***or*** tick". And what can be considered as barUpdate besides tick? Is there any other events fire this method?

      Thank you.

      Comment


        #4
        danilam, a bar update can be two things in NT's event based framework, either the closing of the bar (CalculateOnBarClose = true) or updating the bar with the last received tick / trade (CalculateOnBarClose = false).

        If you just need the last price / bid / ask then working with the Close[0] / GetCurrentBid / GetCurrentAsk would be fine. What is easier in the OnMarketData() is the exact update event timing.

        Comment


          #5
          What do you mean by "exact update event timing"? Could you please explain when it can be better?

          Could you please also answer on this?
          "1. OK, suppose the trade just happened. Which method will fire first of these 2? (As they should fire both simultaneously, I suppose)

          2.Are GetCurrentBid called from onBarUpdate and e.MarketDataType.Bid.Price from onMarketData the same accurate by time?"

          Comment


            #6
            danilam, there's simply no event for a bid / ask update in OnBarUpdate() - it's updated whenever the bar update method is called, this can either be on the close of a bar or on a new tick / last event thus you're limiting to this timing here.

            Comment


              #7
              Thanks, I see what you mean now.
              The last one for now is: Which method of 2 (OBU vs OMD) will fire first, when new trade(tick) arrives?

              Comment


                #8
                With NinjaTrader being multithreaded, you can't rely on a particular call order. OnBarUpdate() gives you the current bid / ask at the time of it's call (CalculateOnBarClose dependent) while OnMarketDate() gives you the values at the time of the specific update event call for either eventarg.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                561 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                325 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                547 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                547 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X