Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Instrument Minute Bar Live Data Not In Sync

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

    Multiple Instrument Minute Bar Live Data Not In Sync

    Hi,

    I've just discovered something which is potentially quite undesirable for those of us who are running live strategies using multiple instruments (e.g. if you were trading a spread or had an indicator which requires simultaneous prices of two or more instruments). My example below trades two instruments.

    In my strategy, I want the key decision making run only once per minute (assuming 1 minute bars) so I have the following check (at the start of OnBarUpdate) to ensure that we only run the code when bars of one of the two instruments triggers OnBarUpdate():
    if (BarsInProgress != 1)
    return;
    In backtesting, everything works as expected as the latest bars for both the primary and secondary instruments seem to be in sync (i.e. Times[0][0] is always the same as Times[1][0]). However, when running live, it seems that about half the time, both bars are not in sync (i.e. Times[0][0] != Times[1][0]).
    if (Times[0][0] == Times[1][0])
    Print("Synced: " + Times[0][0] + " / " + Times[1][0] );
    else
    Print(" Error : " + Times[0][0] + " / " + Times[1][0]);
    Error : 2/20/2019 3:19:00 PM / 2/20/2019 3:20:00 PM
    Synced: 2/20/2019 3:21:00 PM / 2/20/2019 3:21:00 PM
    Synced: 2/20/2019 3:22:00 PM / 2/20/2019 3:22:00 PM
    Error : 2/20/2019 3:22:00 PM / 2/20/2019 3:23:00 PM
    Synced: 2/20/2019 3:24:00 PM / 2/20/2019 3:24:00 PM
    Synced: 2/20/2019 3:25:00 PM / 2/20/2019 3:25:00 PM
    Synced: 2/20/2019 3:26:00 PM / 2/20/2019 3:26:00 PM
    Error : 2/20/2019 3:26:00 PM / 2/20/2019 3:27:00 PM
    In live mode, it is run with calculation set to "on bar close" to minimize the differences between backtesting and live. However, what I see above is problematic if I am relying on two (or more) prices, and one (or more) of them are stale. I believe this problem occurs as the bar doesn't officially "close" until the next bar is formed, which requires a new tick to be received that is bucketed into the following bar. However, ticks after the minute mark for both instruments may come at different times.

    It doesn't seem to be an issue with my data vendor as both Kinetick and Interactive Brokers have demonstrated similar behavior.

    The one thing I had in mind is to put some sort of code at the start of OnBarUpdate to mark what new bars have been received, and to only proceed once all the new bars for the relevant instruments have been received. However, this seems quite clunky and isn't what I would perceive to be the expected behavior in this situation.

    Do you have any recommendations to solve this issue?

    Thanks in advance!

    #2
    Hello wuileng,

    Thank you for your post.

    From the details provided, I could speculate that the differences you are seeing are just the two instruments closing bars at different times. Two instruments will have unique calls to OnBarUpdate and will build individually in real-time so it is possible to see bars closing out of sync depending on the fluidity of the market. In historical data, all data points are known so fixed processing can occur.

    If you can provide your test script along with an example test case I would be happy to review that as well to ensure what we are seeing is just the two instruments building separately.


    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thanks for your response - so basically this is expected behavior based on when the first tick of the following bar is received (which will typically be very marginally different even for liquid instruments)?

      If so, would the best way to implement a strategy/indicator that requires more than one simultaneous price (but also which you only want to run once per bar) would be to create your own data management function at the beginning of OnBarUpdate that checks that all bars are closed (and thus have the same closing timestamp) before proceeding to run the rest of the logic?

      Comment


        #4
        Hello wuileng,

        Yes very likely, if you are printing the values you have shown there is a good chance that could be variable between two separate instruments. As there is no reason these two should be in sync directly you may see differences.

        I did a quick test with the print you provided on a 1 minute series, and can see right now due to the lower volume I was able to recreate this between the NQ and ES:

        Error : 2/21/2019 2:56:00 PM / 2/21/2019 2:57:00 PM
        Error : 2/21/2019 2:56:00 PM / 2/21/2019 2:57:00 PM
        Synced: 2/21/2019 2:57:00 PM / 2/21/2019 2:57:00 PM

        In this case, I saw that the NQ had a tick come in which closed the bar, this called OnBarUpdate and caused a print. The two series were not in sync at that point because we are now waiting on the ES to receive a tick to close its bar which happened a short time after the NQ tick.

        If you are specifically waiting for the instruments times to match, you would likely need to just use the condition you are now to find that point. If you are otherwise just trying to do something once after each series has closed 1 bar you would likely need to add additional logic like you mentioned to manage this situation directly.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        5 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X