Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData vs OnBarUpdate

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

    OnMarketData vs OnBarUpdate

    I have a few questions regarding OnMarketData vs OnBarUpdate:

    1) From my research, it appears that for the most part OnMarketData and OnBarUpdate are the same (when CalculateOnClose = false). However, OnMarketData has a MarketDataEventArgs object, whereas OnBarUpdate has nothing. OnMarketData gets a lot more data, ie. all the changes in bid/asks, etc. OnBarUpdate, will not get the latest bid/ask data the way OnMarketData will. It will only get updates to the bar, so the information it receives is a lot more limited, is this correct? Is this the only difference or are there other subtle differences?

    2) To build further on the previous question, will there always be a corresponding OnMarketData event for every OnBarUpdate event, but not necessarily an OnBarUpdate event for every OnMarketData event? For example, there won't be a corresponding OnBarUpdate for an OnMarketData where e.MarketDataType == MarketDataType.Ask.

    2) Is there a specific order in which OnMarketData and OnBarUpdate get called, ie. does OnMarketData get called before OnBarUpdate, or is there no guarantee? I read in a previous post that there was no guarantee but I just want to verify that is the case.

    3) I know for OnMarketData, if e.MarketDataType == MarketDataType.List, then e.Price is the last price. Assuming CalculateOnClose == false, what value can I use in OnBarUpdate that would tell me the value of the last tick that just came in, ie. the price of the last trade? Is it Close[0] or is it something else?

    4) I want to separate out my indicator code such that it does all the data processing and gathering in the OnMarketData method, and it does all the graphical updating of the indicator in OnBarUpdate. Is this okay to split up the code this way, or is this not recommended and both should occur in the same method, ie. all the code should be in OnBarUpdate or OnMarketData, but not both. I'm wondering if there are performance implications to do this?

    Thanks in advance,

    Ken

    #2
    1. Those would be the key differences.

    2. That is correct.

    3. There is no guarantee on the order. If you want to update plots, you should do it in OnBarUpdate().

    4. If you have no need for bid/ask I would recommend doing it directly in OnBarUpdate() so you don't have to unnecessarily process extra events.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks once again, Josh!

      One followup question:

      I know for OnMarketData, if e.MarketDataType == MarketDataType.Last, then e.Price is the last price. Assuming CalculateOnClose == false, what value can I use in OnBarUpdate that would tell me the value of the last tick that just came in, ie. the price of the last trade? Is it Close[0] or is it something else?

      Comment


        #4
        For OnBarUpdate(), just use the Close[0] then if CalculateOnBarClose set to false.

        Comment


          #5
          Thanks Bertrand. Actually, just one more question... how do I get the exact time for the last tick that came in? I know that Time[0] will give me the time for the bar, but I really need the time of the last tick. Is this possible to get from OnBarUpdate, or does this require OnMarketData?

          Comment


            #6
            You could work with DateTime.Now as you recevie Level 1 events for OnMarketData(), or work with a 1 tick chart in the OnBarUpdate() - in a multiseries strategy use Times to access timestamps of an added series -

            Comment


              #7
              Does OnBarUpdate get every "last price" that OnMarketData gets?

              Comment


                #8
                Yes, if you run OnBarUpdate() on each tick -

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                577 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 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
                553 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X