Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Series T array similar to BarsArray for multi-Time frames?

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

    Series T array similar to BarsArray for multi-Time frames?

    I have several additional series that are derived from the added series of multiple time frames, all for the same instrument, which I would like to store in an array similar to BarsArray so that I can simply refer to each one based upon its index number. Please advise if this would be the correct way to set this up:

    1) at the top of the strategy declare the three element series array OHLC4s:

    private Series<double> [ ] OHLC4s = new Series<double>[3];

    2) in State.Configure add two additional time series to the strategy:

    else if (State == State.Configure)
    {

    AddDataSeries(BarsPeriodType.Second, 30); // BarsArray Index 1
    AddDataSeries(BarsPeriodType.Second, 60); // BarsArray Index 2

    }​

    3) within State.DataLoaded add the following lines:

    else if (State == State.DataLoaded)
    {​

    OHLC4s[0]= new Series<double>(BarsArray[0]); // Synced to BarArray[0]
    OHLC4s[1]= new Series<double>(BarsArray[1]); // Synced to BarArray[1]
    OHLC4s[2]= new Series<double>(BarsArray[2]);​ // Synced to BarArray[2]

    }

    4) Finally, within OnBarUpdate define the the custom series:

    OHLC4s[0][0] = 0.25 * (Opens[0][0] + Highs[0][0] + Lows[0][0] + Closes[0][0]) ;
    OHLC4s[1][0] = 0.25 * (Opens[1][0] + Highs[1][0] + Lows[1][0] + Closes[1][0]) ;
    OHLC4s[2][0] = 0.25 * (Opens[2][0] + Highs[2][0] + Lows[2][0] + Closes[2][0]) ;​

    Is this the correct way to set up a custom array of time series? Would I then be able to call any of the three data series by its index such as OHLC4s[2]? For example, SMA(OHLC4s[2], 10), etc?

    Do I need to do anything else or should I do something differently than what is outlined above?

    Thank you very much for your input/advice.
    Last edited by Dr Kerry; 10-28-2024, 03:21 PM.

    #2
    Hello Dr Kerry,

    You can use C# arrays to hold variables, you would need to assign values to your array like you have. The best way to check if this is correct would be to run the script and print values from each of the series while using the array to make sure no index errors happen.

    Comment


      #3
      Jesse,

      Thank you for your advice. I will set up the printouts and follow up. In the mean time, how is BarsArray constructed to hold multiple T series ?

      Regards,

      Kerry

      Comment


        #4
        Hello Dr Kerry,

        We cannot view the internal source code so that is not something I could answer.

        Comment


          #5
          Jesse,

          The example I gave earlier worked only to the extent that it didn't give any compiler or run-time errors but the stored values were all wrong and produced incorrect results in my strategy calculations when recalling the stored values.Therefore I don't think this the correct way to set up a custom array of time series. If I made OHLC4s a 3xN array how would this help if N is a fixed number, unlike the <T> series which will each have different numbers of entries and are each continually growing with the passage of time. Furthermore how would you assign each element of the <T> series to a specific element of the array?​

          BarsArray seems to be just a convenient wrapper around whatever gets placed inside without reference to the number of elements as evidenced by the fact that it is most useful when implementing multi time-frame strategies. A thirty-second data set will have 10 times more entries than a 5-minute data set and the number of entries in either will continually grow as time moves forward. So it would seem, I think, that the standard fixed 3 x N dimensional array is not exactly what is needed.

          Thank you again,

          Kerry

          Comment


            #6
            Hello Dr Kerry,

            Unfortunately I cannot see the internal code to answer how the internal arrays may work, you could experiment by using arrays but I really couldn't provide any suggestions on that. For series use we just suggest making variables and then using the variables name when accessing series.

            Comment


              #7
              Jesse,

              I devised a workaround that seems to be performing as intended:

              1) Declare several custom series:

              private Series<double> OHLC4s0;
              private Series<double> OHLC4s1;
              private Series<double> OHLC4s2;
              private Series<double> OHLC4s3;
              private Series<double> OHLC4s4;
              private Series<double> OHLC4s5;

              and also the integer parameter BarIdx

              private int BarIdx ;

              2) Add the additional data series to the strategy:

              else if (State == State.Configure)
              {

              AddDataSeries(BarsPeriodType.Second, 30);
              AddDataSeries(BarsPeriodType.Second, 60);
              AddDataSeries(BarsPeriodType.Minute, 2);
              AddDataSeries(BarsPeriodType.Minute, 8);
              AddDataSeries(BarsPeriodType.Minute, 16);
              }​

              3) Sync each series to the appropriate BarsArray for each added series (to ensure each one updates in sync with the corresponding bar series).

              OHLC4s0 = new Series<double>(BarsArray[0]);
              OHLC4s1 = new Series<double>(BarsArray[1]);
              OHLC4s2 = new Series<double>(BarsArray[2]);
              OHLC4s3 = new Series<double>(BarsArray[3]);
              OHLC4s4 = new Series<double>(BarsArray[4]);
              OHLC4s5 = new Series<double>(BarsArray[5]);​

              4) Define the Method OHLC4S:

              private Series<double> OHLC4S(int BarIdx)

              {
              if (BarIdx == 0)
              return OHLC4s0;
              else if (BarIdx == 1)
              return OHLC4s1;
              else if (BarIdx == 2)
              return OHLC4s2;
              else if (BarIdx == 3)
              return OHLC4s3;
              else if (BarIdx == 4)
              return OHLC4s4;
              else if (BarIdx == 5)
              return OHLC4s5;
              else
              return OHLC4s0;
              }​

              5) Give values to each of the custom series:


              OHLC4s0[0] = 0.25 * (Opens[0][0] + Highs[0][0] + Lows[0][0] + Closes[0][0]) ;

              OHLC4s1[0] = 0.25 * (Opens[1][0] + Highs[1][0] + Lows[1][0] + Closes[1][0]) ;

              OHLC4s2[0] = 0.25 * (Opens[2][0] + Highs[2][0] + Lows[2][0] + Closes[2][0]) ;

              OHLC4s3[0] = 0.25 * (Opens[3][0] + Highs[3][0] + Lows[3][0] + Closes[3][0]) ;

              OHLC4s4[0] = 0.25 * (Opens[4][0] + Highs[4][0] + Lows[4][0] + Closes[4][0]) ;
              i
              OHLC4s5[0] = 0.25 * (Opens[5][0] + Highs[5][0] + Lows[5][0] + Closes[5][0]) ;​


              6) Calling OHLCS(int BarIdx) will give the correct data values for the series

              SMA(OHLCS(3), 10); gives the 10 entry SMA for OHLCs3

              OHLCS(2)[0] gives the current value of OHLCs2

              So this behaives very similarly to BarsArray but for custom series.
              Last edited by Dr Kerry; 11-06-2024, 01:30 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              22 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              120 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              63 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              41 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              45 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X