Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AddDataSeries on same instrument with different trading hours

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

    AddDataSeries on same instrument with different trading hours

    Hi!

    I want to add a 1440 minute data series with trading hours template x and another 1440 minute data series with trading hours template y on the same instrument:

    AddDataSeries("ES 06-23", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "Custom Trading Hours X");
    AddDataSeries("ES 06-23", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "Custom Trading Hours Y");​

    However the script only processes the data from the first added data series (Trading Hours X) and not from the second added data series (Trading Hours Y).

    The Help Guide says:
    "When adding multiple Data Series of the same instrument and the same Bar Type, the 'barsToLoad' property will only be effective on the first added series. Subsequent series with a different barsToLoad setting will not load a different number of bars than the first series."
    • Is there a way I can add the same instrument with the 1440 minute data with different trading hours? I tried to create a custom BarsPeriodType with 1440 minutes but couldn't make it work as expected.

    The Help Guide says further: "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."​
    • Does this mean that eg. if Trading Hours Template X goes until 3pm and trading Hours Template Y goes until 5pm OnBarUpdate will not be processed between 3 and 5 pm until the next day open of trading hours template X?
    Thanks in advance!
    Last edited by KirkHammett; 04-06-2023, 05:52 AM.

    #2
    Hello KirkHammett,

    Is it possible the trading hours name template is not matching?

    I've tested on my end and it is loading the data properly.

    Attached is a test script and the output saved to a text file.

    AddDataSeriesTradingHoursTest_NT8.zip
    NinjaScript Output 4_6_2023 7_23 AM.txt

    Is there a way I can add the same instrument with the 1440 minute data with different trading hours? I tried to create a custom BarsPeriodType with 1440 minutes but couldn't make it work as expected.​
    Yes, as demonstrated in the test script, the TradingHours can be changed when using the same instrument.

    Does this mean that eg. if Trading Hours Template X goes until 3pm and trading Hours Template Y goes until 5pm OnBarUpdate will not be processed between 3 and 5 pm until the next day open of trading hours template X?
    It depends on when the trading sessions have started. The script will wait for all trading sessions to be in session.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      thank you very much for the quick response. I am sorry, there was a confusion on my side. I tested it with your code and everything works as expected, thanks a lot!

      As for the realtime handling: Lets assume the following:
      Trading Hours Template X goes from 1am to 10pm
      Trading Hours Template Y goes from 9am to 4pm

      OnBarUpdate will only be processed within 9am to 4pm? Is there any way OnBarUpdate processing from 1am-9am and 4pm-10pm?

      Thank you very much for your help!

      Comment


        #4
        Hello KirkHammett,

        Time conditions are used to trigger actions between certain times.


        Hello, I am building a strategy to use with the MACD indicator and am trying to have it turn on at specific times to place an order. For example, turn on the strategy from 1:30-2:00am and then reactivate at 3:00-3:30am etc. for multiple times throughout the day. I have built 5 separate strategies for the times I want, however

        I'm experiencing a problem when I attempt to use a time value as a user input parameter in my strategy, while testing in optimizer. My objective is to be able to easily change the strategy trading hours from within the optimizer user input parameters. I've programmed time values as user inputs in Builder. However, when I run


        Trading hours are used to limit the available data used for indicator calculations.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I know the difference between time conditions and trading hours. I have 2 strategies trading one instrument combined into one script. One strategy takes the data of trading hours template X and the other one the data of template Y. But everything is in one script. I just want to make sure that everything will work as expected in real time but the help guide confuses me a bit:

          "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."​

          Trading Hours Template X goes from 1am to 10pm
          Trading Hours Template Y goes from 9am to 4pm

          Is OnBarUpdate only be processed within 9am to 4pm realtime? Or is this not what the help guide means?

          Thanks for your help!

          Comment


            #6
            Hello KirkHammett,

            I would expect the scripts to start processing OnBarUpdate at 9:00 AM when both sessions are in session.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              sorry for bothering you again. It behaves as you said. OnBarUpdate processes realtime only when both sessions are in session. However, in historical state it processes whenever it is in any of the sessions. Is there any way I can make it process realtime like in historical state even if one added series is not in session? I have 2 strategies for the same instrument combined in one because it is not recommended to have 2 separate strategies on the same instrument.

              To sum it up: I have two strategies working with two different trading hours templates on the same instrument. Do you have any idea how I can make this work properly?

              Thanks for your help!

              Comment


                #8
                Hello KirkHammett,

                I'm not quite understanding why you are using different trading hours on the same instrument. Can you clarify your goal?

                Unfortunately, I would not have a work around for this. I would instead use a trading hours template that covers all of the hours and control events with time conditions.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for the prompt response. I use a shorter trading hours template strategies to exclude certain data of the day from calculation for one of the strategies and a longer trading hours template for the other strategy to use the data of the full day. I hope this makes it clear.

                  It is not clear to me why realtime it behaves different than in historical state.

                  I would very much appreciate your help!

                  Comment


                    #10
                    Hello KirkHammett,

                    Unfortunately, this is the behavior of using multiple data series with different trading hours, and why there is a warning for this in the help guide.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Then I think the best solution is to have 2 separate strategies and activate them separately even though it is not recommended. Just for my understanding: It is not recommended because the strategy and account position can be out of sync right? So If I check in each strategy the account position before entering a trade I should be fine right? Do you have any tips for running multiple strategies on the same instrument? I would be grateful for any tips you have!

                      Having 2 accounts is no option to me especially because I plan to run more than 2 strategies on the same instrument.

                      Thanks a lot!
                      Last edited by KirkHammett; 04-10-2023, 04:02 PM.

                      Comment


                        #12
                        What I think I would do if I were you is add a single Default 24/7 series and calculate the parts you want in memory so you're just working with the one series. If it requires some complicated indicators that might not be practical, but if it's something simple that would be a lot better than fighting with all these series with their different trading hours.
                        Bruce DeVault
                        QuantKey Trading Vendor Services
                        NinjaTrader Ecosystem Vendor - QuantKey

                        Comment


                          #13
                          Hello KirkHammett,

                          You could choose to run multiple strategies on the same instrument and account, but know that one or both of the strategies will be out of sync with the account.

                          Below is a link to a forum post that discusses.


                          My recommendation would be to use time conditions. If there are indicators that need to calculate with specific data, these would implement those time conditions.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank you both Bruce and Chelsea!

                            I am trying to make it work with time conditions. I tried saving the OHLC values as Series<T> objects with my time conditions but the numbers are equal to those of the primary bar series so this doesn't help as far as I understand it. I also stored the OHLC values within my time conditions in a List but I cannot pass them to the indicators I am using since I need Series objects for the indicators. Do you have any suggestion what is the best way to do this? When working only with OHLC values lists are ok, but with indicators it doesn't work. Any idea?

                            Thanks a lot for your help again, very much appreciated!
                            Last edited by KirkHammett; 04-11-2023, 11:20 AM.

                            Comment


                              #15
                              Hello KirkHammett,

                              I'm not quite understanding the issue. The OHLC are already price data series (including for any added series) which you can supply to an indicator.. You can save your own calculated values in a Series<double>, which will have a slot for each bar. To synchronize to an added price series use the BarsArray[barsInProgressIndex] when constructing.

                              mSeries = new Series<double>(BarsArray[0]);
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              51 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              128 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              69 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              42 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              46 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X