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

CurrentBars disparity when using multiple data series

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

    CurrentBars disparity when using multiple data series

    When I have 2 data series in a strategy with the same time frame of bars (ES 5-minute bars and NQ 5-minute bars in this example), I get a strange result where the CurrentBars of each data series differ, sometimes by 1 bar and sometimes by 2 bars. I've illustrated this in the attachment which shows the output of a simple script that prints the data series name and that data series CurrentBars number on each OnBarUpdate. You can see that in the beginning, these 2 data series differ by 2 bars, then 1 bar, then occasionally 2 bars again (i have read that the currentbars number will start at -1 until all data series have processed, but this wouldnt explain the discrepancy of 2 bars anyway, so must be something else at play here). Each data series should increment by 1 bar on each bar update, however the 2nd data series seems to sometimes not increment at all, and at other times increment by 2. Is there a way to correct this behavior? A way to sync the data series to reliably increment and perhaps have the same CurrentBars number? Thanks in advance...
    Attached Files

    #2
    Hello pkr75,

    That is correct behavior because you are using two different instruments. They are not synced in who trades each instrument so they will have varied times when data comes in to close bars. You would only be able to sync the same instrument on different timeframes, in that case there is an order to which OnBarUpdate is called. For separate instruments you may see that one trades more than the other so there is no reason they should be in sync.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply Jesse, but I am still a bit confused. Both instruments are 5 minute bars, so each instrument's bar should close every 5 minutes, right? Since I am not dealing in ticks, why should it matter if one instrument trades more than the other? Why would each instruments CurrentBars count not incrementally update every five minutes in this case?

      Comment


        #4
        Hello pkr75,

        They may close each 5 minutes or not, they are two different instruments. That depends when each instrument gets data to close the bar. There's not an expectation that two different instruments would be synced up.
        JesseNinjaTrader Customer Service

        Comment


          #5
          You said "that depends when each instrument gets data to close the bar". What does that mean exactly? If a given instrument is synced to the time, then a 1-minute bar, for example, would close when one minute ends and the next one begins when the clock reads XX:00. But it seems like you are saying that it does not solely depend on time, because you say that an instrument needs to get some type of data in order to close the bar. Can you please explain this to me? What data is needed to close the bar? Thanks for your patience.

          Comment


            #6
            From what i've pieced together online, a bar is closed when a tick comes in to create a new bar. Is that correct? If so perhaps my code could check for the first tick of a new bar for each instrument before continuing...

            Comment


              #7
              "In NinjaTrader's event driven framework, bar closures are signaled by the tick that opens the next bar. The price of the last tick of a bar can be referenced by checking Close[1] on IsFirstTickOfBar." ... from the ninjascript reference guide.

              Comment


                #8
                Jesse, I actually just found a reply of yours to a 2014 post which was super helpful ( https://ninjatrader.com/support/foru...cundary-series ). I'll use IsFirstTickOfBar in conjunction with BarsInProgress to do my checks before proceeding in the script. Thanks so much!

                Comment


                  #9
                  Originally posted by pkr75 View Post
                  When I have 2 data series in a strategy with the same time frame of bars (ES 5-minute bars and NQ 5-minute bars in this example), I get a strange result where the CurrentBars of each data series differ, sometimes by 1 bar and sometimes by 2 bars. I've illustrated this in the attachment which shows the output of a simple script that prints the data series name and that data series CurrentBars number on each OnBarUpdate. You can see that in the beginning, these 2 data series differ by 2 bars, then 1 bar, then occasionally 2 bars again (i have read that the currentbars number will start at -1 until all data series have processed, but this wouldnt explain the discrepancy of 2 bars anyway, so must be something else at play here). Each data series should increment by 1 bar on each bar update, however the 2nd data series seems to sometimes not increment at all, and at other times increment by 2. Is there a way to correct this behavior? A way to sync the data series to reliably increment and perhaps have the same CurrentBars number? Thanks in advance...
                  If I'm wrong on this, I apologise. If I recall correctly, Its been a few years, that if a time bar that does not have any trades during the life of the bar, ie 5-minutes, the bar does not print on the chart and a new bar's timer starts. If this happens on one instrument and not the other, a bar count discrepancy occurs.between the two instruments.
                  RJay
                  NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                  Comment


                    #10
                    That makes sense RJay, and thanks for your response. In my particular case, it turned out that the discrepancies occured when my script performed an action immediately after one data series had received its first tick but the other data series had not. Therefore the data series which had received its first tick closed the previous bar and updated its CurrentBars number, while the data series which had not received its first tick had not yet closed the previous bar and consequently not yet moved forward to the next CurrentBars number.

                    Comment


                      #11
                      Hello pkr75,

                      The first tick of a bar closes the previous bar, until a new tick is recieved the bar wont close which may lead to differences in current bar between instruments.

                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by kempotrader, Today, 08:56 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post kempotrader  
                      Started by kempotrader, Today, 08:54 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post kempotrader  
                      Started by mmenigma, Today, 08:54 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post mmenigma  
                      Started by halgo_boulder, Today, 08:44 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post halgo_boulder  
                      Started by drewski1980, Today, 08:24 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post drewski1980  
                      Working...
                      X