Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot make sense of AddDataSeries with RTH and OnBarClose

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

    Cannot make sense of AddDataSeries with RTH and OnBarClose

    I am trying to AddDataSeries using "CME US Index Futures RTH" with 300-minute bars.

    As I understand it "CME US Index Futures RTH" should give me 450 minutes of data per day (09:30-17:00) and if I ask for 300-minute bars then every day I would expect:
    - 1 bar starting at 09:30 and ending at 14:30 (containing 300 minutes)
    - 1 bar starting at 14:30 and ending at 17:00 (the remaining 150 minutes)

    My main chart is just a default NQ 5m chart, with no explicit trading hours set.

    I am logging out the bar times and for the main 5m chart series (BarsInProgress==0) I can see bar closes every 5 minutes, as I would expect.

    However for the added data series (BarsInProgress==1) I seem to get bar closes every few minutes, instead of the two expected bar closing times above.

    If I create a chart in Ninja, and set it to 300-minute and "CME US Index Futures RTH", then I see the two bars per day, with bar closing times as expected,
    but I cannot seem to replicate this expected behaviour in code for some reason.

    Am I being spectacularly stupid and missing something here?

    I have attached an image of the logging output and a .cs file used to demonstrate the issue.

    ​Thanks for any help on this.
    Attached Files

    #2
    Hello gambcl,

    You have BarsPeriodType = Data.BarsPeriodType.Minute, BaseBarsPeriodValue = 300 in AddDataSeries().

    The Minute bar type is a base bar and does not have an underlying bar type. I think you are meaning to use Value and not BaseBarsPeriodValue.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.



    For debugging I do recommend using Print() to the NinjaScript Output window instead of Log() so the information is not written to the log which is used for our staff diagnosing system issues.
    If there is a lot of output I recommend writing the information to a separate text file using C# StreamWriter.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you, Thank you, Thank you!

      It was right in front of me after all!

      My 300m RTH bars are now behaving as expected, and now I think I am about to run into my next problem.

      I need to get the price at 2am, which is obviously outside the CME RTH trading hours used by my 300m data series.

      If I am understanding the docs (and posts in here) correctly then even if I add an additional 1m data series I will not see any real-time calls to OnBarClose until the CME RTH open at 9:30am.
      I am running this with logging overnight to test this theory.

      If that is the case, is there any other way that I might get notified of the price at 2am, and not have to wait until 9:30?

      PS: Also thanks for the logging tip!

      Comment


        #4
        Hello gambcl,

        Correct, OnBarUpdate() does not run until all price series are in session.

        You could choose to use a different script to get an update at 2 am. Or you could choose to use a timer with a BarsRequest.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello again Chelsea,

          I will look into the BarsRequest thanks, haven't heard of this.

          The strange thing is, I left my indicator running overnight, and I WAS getting real-time calls into OnBarUpdate for the added 1-minute series, as well as the chart's 5-minute series.
          I kind of wasn't expecting that. I mean it helps me if it works, but I'm concerned that I am not understanding something and it will not be reliable.

          I added the two data series like this:

          Code:
          AddDataSeries(null, new BarsPeriod { BarsPeriodType = Data.BarsPeriodType.Minute, Value = 300 }, 30, "CME US Index Futures RTH", true);
          AddDataSeries(null, new BarsPeriod { BarsPeriodType = Data.BarsPeriodType.Minute, Value = 1 });
          This is what I see:
          Code:
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 16:59:00
          REALTIME: OnBarUpdate([5 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 17:00:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 17:00:00
          REALTIME: OnBarUpdate([5 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:05:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:01:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:02:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:03:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:04:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:05:00
          REALTIME: OnBarUpdate([5 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:10:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:06:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:07:00
          REALTIME: OnBarUpdate([1 Minute], [CME US Index Futures ETH]): Time = 15/04/2025 18:08:00


          It looks like I am getting realtime 1-minute bars after the "CME US Index Futures RTH" session has closed at 17:00.

          Has the Ninja behaviour changed recently, or is this expected?

          Comment


            #6
            Hello gambcl,

            From the Desktop SDK:
            "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries.​"
            Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


            These may be the queued events.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              If they were queued I was expecting not to see them until the 9:30 open of the "CME US Index Futures RTH" session, but these were coming in live right before my eyes overnight, one every minute.

              Comment


                #8
                Hello gambcl,

                I will inquire with the development team if there has been a change to this.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  OK, so tonight I started running my indicator a bit later, it was 7pm Eastern, so after the 1hr shutdown and then globex open.

                  This time I DID see the added 1-minute bars being queued until the chart's own 5m bars called OnBarUpdate, then I would see five calls for each of the 1-minute bar closes.

                  It's not as bad as waiting until 09:30 when the CME RTH begins, but I still don't want to be waiting for the chart bar to close before I can query these values at the specified times.

                  So it looks like I will have to switch to a timer + BarsRequest.

                  Many thanks for your excellent help in this.

                  Comment


                    #10
                    Hello again Chelsea,

                    I am just reading up on the BarsRequest you suggested, it looks like there are a couple of ways to use it:
                    • request bars in a single call
                    • subscribe to real-time bars
                    If I try to subscribe to the 1-minute real-time bars using BarsRequest, is it hit by the same problem where the bars will be queued?
                    if it is then I really will need to schedule a timer to make a request for bars at the relevant time.

                    Comment


                      #11
                      Hello gambcl,

                      The BarsRequest would be used instead of adding the RTH data series to allow the script to function for the full ETH hours.

                      A BarsRequest is not in sync with the strategy and does not create a data series, but gives you the data requested in it's own methods.

                      No, the real-time updates for the BarsRequest will not be queued.

                      Should you need the data in a series (for example to pass to an indicator), the barsRequest could push data into a custom series that is synchronized to the primary series.
                      Below is a link to an example of this.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks again Chelsea, I think this will get me sorted.

                        The download link for the code does not seem to be working for me however.
                        Is there another link to the Dynamic-Bars-Request code?

                        Comment


                          #13
                          Hello gambcl,

                          I'm not sure why the download link is not working. I'll report this to our IT.

                          Below is a link to where you can find this on the forum.
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          557 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          324 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
                          545 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          547 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X