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

AddDataSeries - Different Trading Hours

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

    AddDataSeries - Different Trading Hours

    Hellos,

    I would like to ADDDataSeries "CME US Index Futures RTH" to an ETH indicator. I'm able to add a different time frame... I've attempted with the strategy builder and reviewed the help guide.

    Thanks in advance.

    #2
    Hello rcmcd,

    Thanks for your post.

    You will need to use one of the following overloads to add a data series with a different Trading Hours template. This cannot be done in Strategy Builder created strategies without first unlocking the code.

    Code:
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName, bool? isResetOnNewTradingDay)
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)
    Our BarsPeriod documentation page has an example that can be referenced for syntax:

    Code:
    protected override void OnStateChange()
    {
        if (State == State.Configure)
        {     
              // add a 1440 minute apple bars object using the RTH session template
              AddDataSeries("AAPL", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "US Equities RTH");               
        }
     
        else if (State == State.DataLoaded)
        {
              // Print out the loaded bars period 
              Print(Instrument.FullName + " " + BarsPeriod); // MSFT 1 Minute
              Print(BarsArray[1].Instrument.FullName + " " + BarsArray[1].BarsPeriod); // AAPL 1440 Minute
        }
    }
    As a tip, you could pass "null" (without quotes) as the instrument name, and the instrument for the primary data series will be used.

    For the thread's reference I will include documentation links for AddDataSeries() and for BarsPeriod. There are important notes to consider when adding additional data to your script. Finally, the Multi Time Frame and Instruments documentation should be referenced for a complete guide to creating and working with a multi series NinjaScript.

    AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm

    BarsPeriod - https://ninjatrader.com/support/help...barsperiod.htm

    Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

    The documentation linked above is publicly available. If you have any additional questions, please don't hesitate to ask.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello rcmcd,

      Thanks for your post.

      You will need to use one of the following overloads to add a data series with a different Trading Hours template. This cannot be done in Strategy Builder created strategies without first unlocking the code.

      Code:
      AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)
      AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName, bool? isResetOnNewTradingDay)
      AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)
      Our BarsPeriod documentation page has an example that can be referenced for syntax:

      Code:
      protected override void OnStateChange()
      {
          if (State == State.Configure)
          {     
                // add a 1440 minute apple bars object using the RTH session template
                AddDataSeries("AAPL", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "US Equities RTH");               
          }
       
          else if (State == State.DataLoaded)
          {
                // Print out the loaded bars period 
                Print(Instrument.FullName + " " + BarsPeriod); // MSFT 1 Minute
                Print(BarsArray[1].Instrument.FullName + " " + BarsArray[1].BarsPeriod); // AAPL 1440 Minute
          }
      }
      As a tip, you could pass "null" (without quotes) as the instrument name, and the instrument for the primary data series will be used.

      For the thread's reference I will include documentation links for AddDataSeries() and for BarsPeriod. There are important notes to consider when adding additional data to your script. Finally, the Multi Time Frame and Instruments documentation should be referenced for a complete guide to creating and working with a multi series NinjaScript.

      AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm

      BarsPeriod - https://ninjatrader.com/support/help...barsperiod.htm

      Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

      The documentation linked above is publicly available. If you have any additional questions, please don't hesitate to ask.
      Still not working.
      I used. AddDataSeries("ES 09-18", Data.BarsPeriodType.Minute, 3, "CME Us Index Futures RTH"); I get errors- CS1502, 1503.

      Please advise.

      Comment


        #4
        Hello rcmcd,

        The error is reporting your syntax is incorrect.

        Looking at the compiler errors, we may see the following:
        NinjaScript File Error Code Line Column
        MyCustomIndicator7.cs Argument 4: cannot convert from 'string' to 'NinjaTrader.Data.MarketDataType' CS1503 51 63
        The compiler sees that you have specified 4 arguments and assumes you are using the 4 argument overload below. With this hint from the compiler in mind, we know that we need to make sure we are using the correct overload.

        Code:
        AddDataSeries(string instrumentName, BarsPeriodType periodType, int period, MarketDataType marketDataType)
        I would suggest testing with the sample code from the BarsPeriod documentation verbatim, and then to change the Trading Hours template to be used to get the proper syntax.

        Code:
        AddDataSeries("AAPL", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "US Equities RTH");
        JimNinjaTrader Customer Service

        Comment


          #5
          I think that worked.

          You're my hero!

          Comment


            #6
            Jim,

            I've got a native data series within a strategy running on tick (value 3 on "US Equities RTH").
            Within State.Configure I have tried to add the additional series as:

            Code:
            AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, "Default 24 x 5");
            I receive the error "strat110922 tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load AAPL Default: Daily" whenever i try and reference that series.

            I have additional data series that work without issue but this was an attempt to reference premarket data from within this native strategy set to "US Equities RTH".

            Any direction on what, I'm sure, I'm missing?

            L

            Comment


              #7
              Hello larkmail,

              Thanks for your note.

              This error is generally generated when the script uses data but the parent script did not add the same data.

              Are you referencing third-party indicators within the strategy?

              If so and you built your own strategy, you will need to know what data that indicator adds and then add the same data in your strategy.

              See the Warning section and Tips section of this help guide page​ about AddDataSeries(): https://ninjatrader.com/support/help...=adddataseries

              Let me know if I may assist further.
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Thanks Brandon,
                So the strategy is referencing an indicator which references three additional data series (the native is set to tick "US Equities RTH"):

                Indicator looks as such:
                Code:
                        }
                .....
                
                else if (State == State.Configure)
                            {
                                AddDataSeries(Data.BarsPeriodType.Minute, 1);
                                AddDataSeries(Data.BarsPeriodType.Day, 1);
                                AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, "Default 24 x 5");​
                            }
                        }
                
                        protected override void OnBarUpdate()
                        {
                            if (
                                CurrentBars[0] < 1
                                || CurrentBars[1] < 1
                                || CurrentBars[2] < 1
                                || CurrentBars[3] < 1
                                )
                                return;​
                Strategy looks as such:
                Code:
                        }
                .....
                ​
                            else if (State == State.Configure)
                            {
                                AddDataSeries(Data.BarsPeriodType.Minute, 1);                                    // 1 Minute
                                AddDataSeries(Data.BarsPeriodType.Day, 1);                                        // 2 Daily
                                AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, "Default 24 x 5");           
                            }
                            else if (State == State.DataLoaded)
                            {    
                                ref_Indicator           = Indicator(Closes[0], true, 0, true, 16, 9, 0);
                            }
                        }
                
                        protected override void OnBarUpdate()
                        {
                            if (
                                CurrentBars[0] < 1 
                                || CurrentBars[1] < 1
                                || CurrentBars[2] < 1
                                || CurrentBars[3] < 1
                                )
                                return;​
                If i comment out the 3rd data series within the indicator and CurrentBars[3] all works well (obviously not able to use that 3rd data series though). If not, i receive that error.

                See anything obvious?

                L

                Comment


                  #9
                  Hello L,

                  Thanks for your note.

                  I do not see anything wrong with the code that you shared.

                  The error could be coming from another indicator that is being referenced in the strategy.

                  Please send me a reduced exported copy of the strategy and the indicators it references so that I may investigate further.

                  Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed. To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.

                  To export a script, go to Control Center > Tools > Export > NinjaScript Addon.

                  I look forward to assisting further.​
                  Brandon H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post Javierw.ok  
                  Started by timmbbo, Today, 08:59 AM
                  2 responses
                  10 views
                  0 likes
                  Last Post bltdavid  
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  41 views
                  0 likes
                  Last Post alifarahani  
                  Working...
                  X