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

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.
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        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.
            BertrandNinjaTrader Customer Service

            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.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by tsantospinto, 04-12-2024, 07:04 PM
                5 responses
                67 views
                0 likes
                Last Post tsantospinto  
                Started by cre8able, Today, 03:20 PM
                0 responses
                6 views
                0 likes
                Last Post cre8able  
                Started by Fran888, 02-16-2024, 10:48 AM
                3 responses
                48 views
                0 likes
                Last Post Sam2515
                by Sam2515
                 
                Started by martin70, 03-24-2023, 04:58 AM
                15 responses
                115 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by The_Sec, Today, 02:29 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X