• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting data from onmarketdata() to onbarupdate() timing issue

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

    Getting data from onmarketdata() to onbarupdate() timing issue

    Hi guys,
    I have a question about the OnMarketData method Note 7. It states that The OnMarketData() method is guaranteed to always be called after OnBarUpdate(). This creates a data timing problem when data from the last OnMarketData is needed for calculations in OnBarUpdate when the bar closes.
    e.g. Calculate = On bar close. Data is being collected in OnMarketData for calculations to be done in OnBarUpdate. When the bar closes OnBarUpdate executes first but data from OnMarketData, that belongs to that bar, is needed first. Otherwise, the data from OnMarketData will be placed/used in the next bar, not the bar it belongs to.
    When running on a tick chart, the very last tick that closes the bar, it's OnMarketData event occurs after OnBarUpdate, so OnBarUpdate executes and the bar is closed. Then, OnMarketData executes and the last tick’s data is not available to the bar that just closed.

    Is this understanding correct? Or, is there more to Note 7 that needs clarification?
    Thanks.



    PS The forum logged me out before I finished typing my question. You should really increase the log-out time setting.
    Last edited by zacwhitesi; 01-11-2019, 02:35 PM.
    zacwhitesi
    NinjaTrader Ecosystem Vendor - Shark Indicators

    #2
    Hello zacwhiteso,
    Thanks for your post.


    The designed behavior is for OnBarUpdate to come before OnMarketData, allowing for the internal indexes to be updated correctly for the upcoming OnMarketData calls. This also ensures that you receive an OnMarketData update in sync with the tick that closed the bar. It is best to think of the Bars being the primary input to the indicator, and the OnMarketData event to be a sub-set of the bar event.

    Also, the graphic inside the Tick Replay section of the Help Guide can be useful for visualizing this topic: https://ninjatrader.com/support/help...ick_replay.htm

    After doing some additioanl research it looks like the order of events would be:
    1) As the next tick of the next bar comes in and closes the previous bar.
    2) Then an 'on bar close' calculated indicator would have its OnBarUpdate() method triggered.
    3) All OMD events that factored into building the bar have been called prior to the closing OnBarUpdate() method was triggered.
    4) The OMD event that triggered closing the bar is called in the context of the next CurrentBar. (After OBU was called closing the previous bar)

    If this does not work for you then perhaps it would be easiest to add a 1 tick series to the strategies OnBarUpdate to get the more granular timestamps.

    I also feel it may be helpful to let you know that one of our developers made the following notes on this subject:

    1) In principle ALL NinjaScript OnBarUpdate logic triggered 'on bar close' will not trigger until the 'next' tick of the next bar is actually received (Since we don't know to close the current bar until we get the first tick of the next bar)

    2) NinjaScript objects which have OnBarUpdate logic triggered 'on each tick' is subject to the same rules above since you want the same actual ticks reflected in the same bar.

    3) If you have code which you do not want to wait for the next tick to trigger, then you must alter your code accordingly. Specifically in Volume analysis you would trigger all actions directly in OnMarketData and basically not use OnBarUpdate.


    Let me know if I can clarify any of this further.
    Last edited by NinjaTrader_JoshG; 01-14-2019, 08:12 AM.
    JoshNinjaTrader Customer Service

    Comment


      #3
      Thanks Josh
      zacwhitesi
      NinjaTrader Ecosystem Vendor - Shark Indicators

      Comment


        #4
        Originally posted by NinjaTrader_JoshG View Post
        Hello zacwhiteso,

        Let me know if I can clarify any of this further.
        please, if you may, try to clarify again all this in a way so that it becomes understandable also users of NT who are not programmers. Unfortunately to me all this sounds like an extraterrestrial language, but I guess these are important concepts for finally understanding (and then using in trading) how NT8 works.
        The same applies to this, English at light speed, fast video https://www.youtube.com/watch?v=gyel6m3VIWs
        “Understanding NinjaScript Lifecycle and How to Use OnStateChange() in NinjaTrader”
        Thanks.


        Comment


          #5
          guidoisot,

          The information above is about as simple as I can make it. If you have a specific question about my post I will be more than happy to explain it further to the best of my ability.

          In regards to the YouTube link you posted, I suggest creating a separate post to discuss that item as it is not relevant to this thread.
          JoshNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by psquare, Today, 03:11 PM
          4 responses
          18 views
          0 likes
          Last Post psquare
          by psquare
           
          Started by ballboy11, Today, 03:20 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by tonynt, Today, 02:18 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_JoshG  
          Started by denalek2419, Today, 01:46 PM
          3 responses
          12 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by REI140205, Today, 12:58 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Jim  
          Working...
          X