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

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.
    Josh G.NinjaTrader 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.
          Josh G.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by i019945nj, 12-14-2023, 06:41 AM
          3 responses
          60 views
          0 likes
          Last Post i019945nj  
          Started by TraderBCL, Today, 04:38 AM
          2 responses
          17 views
          0 likes
          Last Post TraderBCL  
          Started by martin70, 03-24-2023, 04:58 AM
          14 responses
          106 views
          0 likes
          Last Post martin70  
          Started by Radano, 06-10-2021, 01:40 AM
          19 responses
          610 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          471 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X