Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to create an array contain multi data series

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

    #16
    Good morning, Chris,

    I would now like to include an array of RTY data to the script (RTY5minute,15minute, 60minute, 1daily). I've already combined the RTY data series with the ES data series. I just don't know how to add the second array of data. Do I code it like this:

    ES5[0][0], ES15[1][0], ES60[2][0], ES1DY[3][0], RTY5[4][0], RTY15[5][0], RTY60[6][0], RTY1DY[7][0].


    protected override void OnBarUpdate()
    { if(BarsInProgress == 7)
    { if(CurrentBars[7] < 1) return;

    Thanks.

    Comment


      #17
      Hello AdeptistJune, thanks for your reply.

      The BarsInProgress index will tell you what series OnBarUpdate is processing. It starts with BarsInProgress = 0 for the primary series and counts up for each call to AddDataSeries. So the second series would be BarsInProgress = 1, third BarsInProgress = 2, forth BarsInProgress = 4, and so on. Please see this documentation on the subject:



      Best regards.

      Comment


        #18
        Good Morning, Chris

        I would first like to say: Thanks for all the help you have provided. This project has given me a better understanding of C#. I've added 20 data series to the script. But in the OnBarUpdate, when I use:

        if(BarsInProgress == 1)
        {
        if(CurrentBars[19] < 1)
        return;

        I get an "Out of Range" error message. When I use:

        if(BarsInProgress == 1)
        {
        if(CurrentBars[11] < 1)
        return;

        The code works just fine. I'm just curious of why. I would think I would get an out of range message with CurrentBars[11] instead of the CurrentBars[19]. So why is this?

        Thanks.

        Comment


          #19
          Hello AdeptistJune, thanks for your reply. I'm happy to help out.

          If you want the code to be truly safe from indexing errors, you would check for at least one bar in every single added series. Unfortunately, I can not tell why the script works in these two different scenarios from this snippet.

          Comment


            #20
            Chris

            Can I email you the code and you check it?

            Thanks.

            Comment


              #21
              Hello AdeptistJune, thanks for your reply.

              Please note, it is against our policy to review or debug or review custom scripts. This is so we can provide the same high level of service to all of our clients. To debug a problem like this, first double-check all of the series you are adding to the script. If you can not see this issue upfront use the Print method to print data properties from the script as it runs if you would like to find the precise problem this is causing. This would take a lot of prints if you are dealing with 20 series. Adding a check for at least one bar in each series before accessing a prior index would be the most straight forward. Could you share the State.Configure section of your code where you are adding the series?

              I look forward to hearing from you.

              Comment


                #22
                Thanks Chris,

                Here's what you asked for:


                AddDataSeries("ES 12-20", Data.BarsPeriodType.Minute, 15);
                AddDataSeries("ES 12-20", Data.BarsPeriodType.Minute, 60);
                AddDataSeries("ES 12-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                // AddDataSeries("ES 12-20", BarsPeriodType.Day, 1);

                AddDataSeries("RTY 12-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                AddDataSeries("RTY 12-20", Data.BarsPeriodType.Minute, 15, Data.MarketDataType.Last);
                AddDataSeries("RTY 12-20", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);
                AddDataSeries("RTY 12-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                // AddDataSeries("RTY 12-20", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);

                AddDataSeries("DX 12-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                AddDataSeries("DX 12-20", Data.BarsPeriodType.Minute, 15, Data.MarketDataType.Last);
                AddDataSeries("DX 12-20", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);
                AddDataSeries("DX 12-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                // AddDataSeries("DX 12-20", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);

                AddDataSeries("VX 10-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                AddDataSeries("VX 10-20", Data.BarsPeriodType.Minute, 15, Data.MarketDataType.Last);
                AddDataSeries("VX 10-20", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);
                AddDataSeries("VX 10-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);


                AddDataSeries("ZN 12-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                AddDataSeries("ZN 12-20", Data.BarsPeriodType.Minute, 15, Data.MarketDataType.Last);
                AddDataSeries("ZN 12-20", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);
                AddDataSeries("ZN 12-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);

                protected override void OnBarUpdate()
                {
                if(BarsInProgress == 1)
                {
                if(CurrentBars[11] < 1)
                return;

                Comment


                  #23
                  Hello AdeptistJune, thanks for your reply.

                  The 19th data series is not the largest series added. You would want to check for at least 1 bar in each of the 60 minute series. That way you will know that the smaller series all have at least one bar.

                  Kind regards.

                  Comment


                    #24
                    Sorry Chris, I don't understand. Can you give me an example?

                    Thanks.

                    Comment


                      #25
                      Hello AdeptistJune, thanks for your reply.

                      Currently, if you check the 19th series for 1 bar you are checking for at least one 5 minute bar. You are getting the error because there is not a 60 minute bar loaded at this time, so checking for:

                      if(CurrentBars[2]) should be sufficient.

                      Comment


                        #26
                        Chris,

                        I just tried to compile the code, but I got this error message:

                        Indicator 'MultiTimeFramTest2': Error on calling 'OnBarUpdate' method on bar 23: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                        Is this correct:

                        protected override void OnBarUpdate()
                        {
                        if(BarsInProgress == 1)
                        {
                        if(CurrentBars[2] < 1)
                        return;

                        Thanks.

                        Comment


                          #27
                          Hello AdeptistJune, thanks for your reply.

                          What is the furthest back the script is looking? Is there any part of code in OnBarUpdate that is accessing further back than 2 bars in any scenario? I wanted to also mention that starting with a script that has 20 series with different time frames is not the best starting point for a beginner in multi-time frame scripts. I would recommend starting with something more simple to get a firm grasp on how bars series are processed in a multi time frame script. Please carefully read all sections of this help guide page:



                          Kind regards.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          683 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          386 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          111 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          584 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          585 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X