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

Multi-series & OnBarUpdate ordering of events

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

    Multi-series & OnBarUpdate ordering of events

    Hello,

    I'm attempting to better understand the ordering of events inside OnBarUpdate. I understand this is all event driven and triggered by each incoming tick. A few questions:

    Assuming a chart with SPY 1min (Primary), and then I Add(QQQ, 1min) Secondary, both very active issues.

    1) If COBC=true, will SPY (BarsInProgress == 0) ALWAYS be the first of the two series to call the OnBarUpdate routine when a new bar is closed/finalized? Or will it be random depending on which of the two series delivers the "closing" tick first?

    2) Again with COBC=true...

    if (BarsInProgress == 0) {
    myCalc = Closes[0][0] + Closes[1][0];
    }

    ...will the timestamp associated with the Secondary series (Closes[1][0]), be the same as the Primary at this point in time (inside BarsInProgress == 0), or do I have to wait until the next tick even where BarsInProgress == 1 before the timestamp will be updated?

    In other words, suppose it's the finalizing of the 9:50am SPY 1min bar that triggers the OnBarUpdate. Closes[0][0] will be the closing price of SPY at 9:50am. Will Closes[1][0] be the closing price for 9:50am also, or will it still be the 9:49am price and I will not have access to 9:50 until the Secondary makes a call to OnBarUpdate?

    3) Now with COBC=false...

    if (BarsInProgress == 0) {
    myCalc = Closes[0][0] + Closes[1][0];
    }

    ...same question, will Closes[1][0] have access to the most recent tick of the Secondary while being called inside (BarsInProgress == 0), or does the most recent Secondary series tick "not exist" until it makes it's way through the OnBarUpdate routine?

    #2
    Originally posted by ntfred View Post
    Hello,

    I'm attempting to better understand the ordering of events inside OnBarUpdate. I understand this is all event driven and triggered by each incoming tick. A few questions:

    Assuming a chart with SPY 1min (Primary), and then I Add(QQQ, 1min) Secondary, both very active issues.

    1) If COBC=true, will SPY (BarsInProgress == 0) ALWAYS be the first of the two series to call the OnBarUpdate routine when a new bar is closed/finalized? Or will it be random depending on which of the two series delivers the "closing" tick first?

    2) Again with COBC=true...

    if (BarsInProgress == 0) {
    myCalc = Closes[0][0] + Closes[1][0];
    }

    ...will the timestamp associated with the Secondary series (Closes[1][0]), be the same as the Primary at this point in time (inside BarsInProgress == 0), or do I have to wait until the next tick even where BarsInProgress == 1 before the timestamp will be updated?

    In other words, suppose it's the finalizing of the 9:50am SPY 1min bar that triggers the OnBarUpdate. Closes[0][0] will be the closing price of SPY at 9:50am. Will Closes[1][0] be the closing price for 9:50am also, or will it still be the 9:49am price and I will not have access to 9:50 until the Secondary makes a call to OnBarUpdate?

    3) Now with COBC=false...

    if (BarsInProgress == 0) {
    myCalc = Closes[0][0] + Closes[1][0];
    }

    ...same question, will Closes[1][0] have access to the most recent tick of the Secondary while being called inside (BarsInProgress == 0), or does the most recent Secondary series tick "not exist" until it makes it's way through the OnBarUpdate routine?
    I haven't seen NT internal code,

    But with what I remember to #1 - there's no guarantee to anything from what I've been told here. I believe NT Brett or NT Bertrand has mentioned this... but I'm not sure it has been entirely tested..

    But with #2 and #3 - wouldn't a simple test prove this out?

    And even further, you could also test #1...

    If you get a all ducks and no gooses, then it probably would be TRUE.... (although you never would know if a goose was possible and it might happen ).. (sorry my days in Logic Class from 20 years ago causing flashbacks...)...

    Comment


      #3
      ntfred, NT is a purely an event based framework - so running realtime there's no guarantee for a given call sequence, it would depend on when the exact closing tick would be seen and thus the bar updates triggered. If you're in BIP 0, then you cannot rely on BIP1 having updated as well - especially true if different instruments are involved.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thanks Sledge, reminds me of Taleb's argument... 1,000 observations of white swans cannot disprove the existence of a Black Swan.

        Comment


          #5
          Thank you Bertrand,

          I understand the ordering question now... there is no order. The last question remains unanswered...

          3) Now with COBC=false...

          if (BarsInProgress == 0) {
          myCalc = Closes[0][0] + Closes[1][0];
          }

          will Closes[1][0] have access to the most recent tick of the Secondary while being called inside (BarsInProgress == 0), or does the most recent Secondary series tick "not exist" until it makes it's way through the OnBarUpdate routine?

          Another way of saying it.... suppose my code is really complex and takes a while to calculate (like 2 seconds). At the very end of all the calcs (still inside BarsInProgress == 0) the code makes a call to Closes[1][0]. Will the absolute most recent tick for Closes[1][0] be accessible (liquid issues with 100's of ticks per second)? Or will I only have access to the Closes[1][0] tick that occurred just prior to OnBarUpdate being called by the BIP=0 tick?

          Comment


            #6
            Yes it will have the most recent value if COBC = false

            To test and verify you could do something like this

            Code:
            			if(Historical)
            				return;
            			
            			if (BarsInProgress != 0)
            				return;
            			
            			Print(Closes[0][0] + " " + Closes[1][0] + " " + Closes[2][0]);
            You will see that all three closes will have the same value when run in real time
            LanceNinjaTrader Customer Service

            Comment


              #7
              Ran a test... here is what I've found:

              FOUR quadrants...
              COBC=true/false, historical/real-time

              Q1>> for historical COBC=true
              - likely ordered. seems like bars are always processed in order BIP=0, then BIP=1 (assuming RTH... ETH not so, depends on if there were any trades)
              - timestamps match... when BIP=0 or 1 calls OnBarUpdate, C0 & C1 have same timestamp

              Q2>> for real-time COBC=true
              - Not ordered... BIP=0/1 comes in with no pattern
              - times DO NOT match on first bar of new time, but do match on second bar

              COBC=true, 1min, SPY Primary, QQQ Secondary via Add()
              Code:
              Print("BIP=" + BarsInProgress + "\tSPY>  " + Closes[0][0].ToString("N2") + "    " + Times[0][0].ToString("hh:mm:ss") + "\tQQQ>  " + Closes[1][0].ToString("N2") + "    " + Times[1][0].ToString("hh:mm:ss") + (Times[0][0]==Times[1][0] ? "\tTIMES MATCH":"") + (Historical ? "\tHistorical":""));
              
              BIP=0	SPY>  155.13    09:58:00	QQQ>  21.77    09:58:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.13    09:58:00	QQQ>  21.77    09:58:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.12    09:59:00	QQQ>  21.77    09:59:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.12    09:59:00	QQQ>  21.77    09:59:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.15    10:00:00	QQQ>  21.75    10:00:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.15    10:00:00	QQQ>  21.75    10:00:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.14    10:01:00	QQQ>  21.77    10:01:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.14    10:01:00	QQQ>  21.77    10:01:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.12    10:02:00	QQQ>  21.77    10:02:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.12    10:02:00	QQQ>  21.77    10:02:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.12    10:03:00	QQQ>  21.76    10:03:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.12    10:03:00	QQQ>  21.76    10:03:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.13    10:04:00	QQQ>  21.76    10:03:00
              BIP=1	SPY>  155.13    10:04:00	QQQ>  21.77    10:04:00	TIMES MATCH
              BIP=0	SPY>  155.10    10:05:00	QQQ>  21.77    10:04:00
              BIP=1	SPY>  155.10    10:05:00	QQQ>  21.77    10:05:00	TIMES MATCH
              BIP=0	SPY>  155.08    10:06:00	QQQ>  21.77    10:05:00
              BIP=1	SPY>  155.08    10:06:00	QQQ>  21.80    10:06:00	TIMES MATCH
              BIP=1	SPY>  155.08    10:06:00	QQQ>  21.77    10:07:00
              BIP=0	SPY>  155.11    10:07:00	QQQ>  21.77    10:07:00	TIMES MATCH
              BIP=0	SPY>  155.13    10:08:00	QQQ>  21.77    10:07:00
              BIP=1	SPY>  155.13    10:08:00	QQQ>  21.74    10:08:00	TIMES MATCH
              BIP=1	SPY>  155.13    10:08:00	QQQ>  21.70    10:09:00
              BIP=0	SPY>  155.17    10:09:00	QQQ>  21.70    10:09:00	TIMES MATCH
              BIP=0	SPY>  155.16    10:10:00	QQQ>  21.70    10:09:00
              BIP=1	SPY>  155.16    10:10:00	QQQ>  21.71    10:10:00	TIMES MATCH
              BIP=0	SPY>  155.17    10:11:00	QQQ>  21.71    10:10:00
              BIP=1	SPY>  155.17    10:11:00	QQQ>  21.70    10:11:00	TIMES MATCH
              BIP=0	SPY>  155.15    10:12:00	QQQ>  21.70    10:11:00
              BIP=1	SPY>  155.15    10:12:00	QQQ>  21.73    10:12:00	TIMES MATCH
              BIP=0	SPY>  155.17    10:13:00	QQQ>  21.73    10:12:00
              BIP=1	SPY>  155.17    10:13:00	QQQ>  21.73    10:13:00	TIMES MATCH
              BIP=1	SPY>  155.17    10:13:00	QQQ>  21.73    10:14:00
              BIP=0	SPY>  155.17    10:14:00	QQQ>  21.73    10:14:00	TIMES MATCH
              BIP=0	SPY>  155.19    10:15:00	QQQ>  21.73    10:14:00
              BIP=1	SPY>  155.19    10:15:00	QQQ>  21.71    10:15:00	TIMES MATCH
              BIP=0	SPY>  155.21    10:16:00	QQQ>  21.71    10:15:00
              BIP=1	SPY>  155.21    10:16:00	QQQ>  21.70    10:16:00	TIMES MATCH
              BIP=0	SPY>  155.22    10:17:00	QQQ>  21.70    10:16:00
              BIP=1	SPY>  155.22    10:17:00	QQQ>  21.69    10:17:00	TIMES MATCH
              Q3>> for historical COBC=false
              - appears to be same as COBC=true... ordered and times match.

              Q4>> for real-time COBC=false
              - Not ordered... BIP=0/1 comes in with no pattern... usually BIP=0 calls it first, but not always. (and in this case SPY is the most active)
              - times DO NOT match on first bar of new time...won't match until a tick from the "lagging" issue comes in.
              *** Sometimes a new bar will form, and the next tick to arrive from the lagging issue will still be of the OLD timestamp. (see below in magenta)

              blue = first tick with new bar time
              (Output truncated to focus on areas where a new bar formed)
              Code:
              BIP=0	SPY>  155.24    10:47:00	QQQ>  21.71    10:47:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.24    10:47:00	QQQ>  21.71    10:47:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.24    10:48:00	QQQ>  21.70    10:48:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.24    10:48:00	QQQ>  21.70    10:48:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.29    10:49:00	QQQ>  21.68    10:49:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.29    10:49:00	QQQ>  21.68    10:49:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH	Historical
              BIP=1	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH	Historical
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:50:00	QQQ>  21.68    10:50:00	TIMES MATCH
              ...removed...
              BIP=0	SPY>  155.29    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.29    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.29    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=1	SPY>  155.29    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              BIP=0	SPY>  155.29    10:50:00	QQQ>  21.67    10:50:00	TIMES MATCH
              [COLOR="blue"]BIP=0[/COLOR]	SPY>  155.29    [COLOR="Blue"]10:51:00[/COLOR]	QQQ>  21.67    10:50:00
              BIP=0	SPY>  155.29    10:51:00	QQQ>  21.67    10:50:00
              BIP=0	SPY>  155.29    10:51:00	QQQ>  21.67    10:50:00
              BIP=0	SPY>  155.30    10:51:00	QQQ>  21.67    10:50:00
              [COLOR="blue"]BIP=1[/COLOR]	SPY>  155.30    10:51:00	QQQ>  21.66    [COLOR="Blue"]10:51:00[/COLOR]	TIMES MATCH
              BIP=1	SPY>  155.30    10:51:00	QQQ>  21.67    10:51:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              ...removed...
              BIP=0	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:51:00	QQQ>  21.66    10:51:00	TIMES MATCH
              [COLOR="blue"]BIP=0[/COLOR]	SPY>  155.30    [COLOR="blue"]10:52:00[/COLOR]	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.29    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              [COLOR="Magenta"]BIP=1[/COLOR]	SPY>  155.30    10:52:00	[COLOR="Magenta"]QQQ>  21.66    10:51:00[/COLOR]
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:51:00
              BIP=0	SPY>  155.31    10:52:00	QQQ>  21.66    10:51:00
              [COLOR="blue"]BIP=1[/COLOR]	SPY>  155.31    10:52:00	QQQ>  21.66    [COLOR="blue"]10:52:00[/COLOR]	TIMES MATCH
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:52:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.66    10:52:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.66    10:52:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:52:00	QQQ>  21.66    10:52:00	TIMES MATCH
              ...removed...
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:52:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:52:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.66    10:52:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.66    10:52:00	TIMES MATCH
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.66    10:52:00	TIMES MATCH
              [COLOR="blue"]BIP=1[/COLOR]	SPY>  155.30    10:52:00	QQQ>  21.67    [COLOR="blue"]10:53:00[/COLOR]
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.66    10:53:00
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:53:00
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:53:00
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:53:00
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:53:00
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:53:00
              BIP=1	SPY>  155.30    10:52:00	QQQ>  21.67    10:53:00
              [COLOR="blue"]BIP=0[/COLOR]	SPY>  155.30    [COLOR="blue"]10:53:00[/COLOR]	QQQ>  21.67    10:53:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:53:00	QQQ>  21.67    10:53:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:53:00	QQQ>  21.67    10:53:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:53:00	QQQ>  21.67    10:53:00	TIMES MATCH
              BIP=0	SPY>  155.30    10:53:00	QQQ>  21.67    10:53:00	TIMES MATCH
              Last edited by ntfred; 03-15-2013, 07:34 PM.

              Comment


                #8
                Originally posted by ntfred View Post
                Thanks Sledge, reminds me of Taleb's argument... 1,000 observations of white swans cannot disprove the existence of a Black Swan.
                That's probably what I meant

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by FrancisMorro, Today, 03:24 AM
                0 responses
                1 view
                0 likes
                Last Post FrancisMorro  
                Started by Segwin, 05-07-2018, 02:15 PM
                10 responses
                1,770 views
                0 likes
                Last Post Leafcutter  
                Started by Rapine Heihei, 04-23-2024, 07:51 PM
                2 responses
                31 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by Shansen, 08-30-2019, 10:18 PM
                24 responses
                944 views
                0 likes
                Last Post spwizard  
                Started by Max238, Today, 01:28 AM
                0 responses
                11 views
                0 likes
                Last Post Max238
                by Max238
                 
                Working...
                X