Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-instrument bars are not fed in the (imho) correct order

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

    Multi-instrument bars are not fed in the (imho) correct order

    Dear Sirs,

    first, please confirm that CurrentBarArray[] is exactly the same (an alias of) as CurrentBars[]. I found the former in an imported indicator (PairsCorrelation) from this forum, but afaik it is not documented.

    Now the more serious thing:

    I found in some cases that calls to the OnBarUpdate() event appear to happen in whatever order (i.e. historical bars belonging to different instruments but closing at the same time, are not passed on to the OnBarUpdate() event at the same time).

    Code:
    protected override void OnBarUpdate()
            {
                Print("CurrentBars[0] = " + CurrentBars[0]);
                Print("CurrentBars[1] = " + CurrentBars[1]);
            .....
            }
    The output window shows:

    CurrentBars[0]=0
    CurrentBars[1]=-1
    CurrentBars[0]=1
    CurrentBars[1]=-1
    CurrentBars[0]=2
    CurrentBars[1]=-1
    CurrentBars[0]=3
    CurrentBars[1]=-1
    CurrentBars[0]=4
    CurrentBars[1]=-1
    ...
    ...
    CurrentBars[0]=X
    CurrentBars[1]=0
    CurrentBars[0]=X
    CurrentBars[1]=1
    CurrentBars[0]=X
    CurrentBars[1]=2
    CurrentBars[0]=X
    CurrentBars[1]=3
    CurrentBars[0]=X
    CurrentBars[1]=4
    ...
    ...

    Before you ask, yes, both instruments overlap in time (but not all the time).

    So, the questions are,

    (1) first to confirm wether this is a bug or expected behaviour.

    (2) Then, how can I force an indicator (or strategy) to make calculations with bars of all instruments closing at the same time. It should be easy to check bar closing times, and checking that closing times match across instruments, but I need to have the bar values of same-time-bars simultaneously available.

    (3) I assume that in some of the instruments I can have gaps without bar data. How can I check for these?

    Thank you very much.

    #2
    BenComo,

    Generally if something isn't documented it means its not supported code. We would always recommend using supported items. I will attempt to investigate this and get back to you as soon as I am able.

    (2) Then, how can I force an indicator (or strategy) to make calculations with bars of all instruments closing at the same time. It should be easy to check bar closing times, and checking that closing times match across instruments, but I need to have the bar values of same-time-bars simultaneously available.
    OnBarUpdate() is called for each instrument separately, it will be called for example, twice if you have two series and they both close. The only real way to check that all your series are closed would be to track it in some sort of variable list or something.

    (3) I assume that in some of the instruments I can have gaps without bar data. How can I check for these?
    How do you define a gap? I would say maybe using something like :

    if ( Math.Abs( Close[0] - Open[1] ) > 1*TickSize )
    {

    }
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      I have been misunderstood. Mostly my fault, sorry. Let me rephrase...

      Generally if something isn't documented it means its not supported code. We would always recommend using supported items. I will attempt to investigate this and get back to you as soon as I am able.
      Thanks! Looking forward to it.

      OnBarUpdate() is called for each instrument separately, it will be called for example, twice if you have two series and they both close. The only real way to check that all your series are closed would be to track it in some sort of variable list or something.
      This is not an answer to my intended question. What I need is a way to check or ensure that, within OnBarUpdate() body, I access bars of different instruments and all these bars were closed at the same time. In other words, I do not want that Closes[X][Z] and Closes[Y][Z] (where Z might be 0 or any other value) return values belonging to different moments in the time axis (both instruments X and Y have the same bar size, say 1 minute bars).

      How do you define a gap?
      I was not specific enough, sorry. You understood price gaps, but I meant time gaps, periods of time, intervals in the time axis, without bar data. I discovered that CurrentBar always returns consecutive values, but it is possible that from CurrentBar==X to CurrentBar==X+1 a lot of time passed without bar data.

      This is connected to my previous question, because it can lead the indicator to operate with, say, Closes[X][3] and Closes[Y][3] and the returned values do not belong to the same instant in time, although Closes[X][0] and Closes[Y][0] do... if such a gap existed between Closes[][3] and Closes[][2].

      Comment


        #4
        Bencomo,

        This is not an answer to my intended question. What I need is a way to check or ensure that, within OnBarUpdate() body, I access bars of different instruments and all these bars were closed at the same time. In other words, I do not want that Closes[X][Z] and Closes[Y][Z] (where Z might be 0 or any other value) return values belonging to different moments in the time axis (both instruments X and Y have the same bar size, say 1 minute bars).
        CurrentBars would be the way to check this. Compare if the current value is 1 more than the previous value on each series, this would be the easiest way to check. CurrentBars[x] won't always be the same value.

        I was not specific enough, sorry. You understood price gaps, but I meant time gaps, periods of time, intervals in the time axis, without bar data. I discovered that CurrentBar always returns consecutive values, but it is possible that from CurrentBar==X to CurrentBar==X+1 a lot of time passed without bar data.
        You can check the time stamps of bars by using Times[X][Y], or you can use something like DateTime.Now to get the current time and compare to some previous time you recorded (this only works in real-time however).

        This is connected to my previous question, because it can lead the indicator to operate with, say, Closes[X][3] and Closes[Y][3] and the returned values do not belong to the same instant in time, although Closes[X][0] and Closes[Y][0] do... if such a gap existed between Closes[][3] and Closes[][2].
        Let me know if you need additional information here.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X