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

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

        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 -

            BertrandNinjaTrader Customer Service

            Comment


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

              Comment


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

                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Sparkyboy, Today, 10:57 AM
                0 responses
                0 views
                0 likes
                Last Post Sparkyboy  
                Started by TheMarlin801, 10-13-2020, 01:40 AM
                21 responses
                3,916 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by timmbbo, 07-05-2023, 10:21 PM
                3 responses
                152 views
                0 likes
                Last Post grayfrog  
                Started by Lumbeezl, 01-11-2022, 06:50 PM
                30 responses
                809 views
                1 like
                Last Post grayfrog  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Erick  
                Working...
                X