Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Container similar to BarsArray

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

    Custom Container similar to BarsArray

    I have several custom <T> series in my strategy. It would be very convenient, and save lots of lines of repetitive coding, if I could place all of them in a single container, or collection, with one name, similar to BarsArray, and then just use the container's name with an index number to refer to each of these individual custom <T> series, exactly like BarsArray.

    Can this be done within Ninja's C# framework? If so, how? Any relevant coding examples would be most helpful and appreciated.

    Thank you very much,

    Kerry
    Last edited by Dr Kerry; 11-01-2024, 01:04 AM.

    #2
    Hello Dr Kerry,

    Thank you for your post.

    You could create your own multi dimensional array. We don't have any specific example code as this is considered more general C# education. However you can find plenty of resources online.

    Below are the results from a quick Google search.

    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


    Comment


      #3
      Gaby,

      Will your suggestion work? Suppose I have three custom <T> series and I create a standard fixed 3 x N element array in C# to hold each one of these series. If I understand correctly, as time moves on, wont the the number of elements for each <T> series continually grow and eventually potentially exceed N? 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 to 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.

      For example I tried the following:

      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.

      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]) ;​

      This 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?



      Thank you very much, once again, for your input/advice.​

      Comment


        #4
        Hello Dr Kerry,

        Unfortunately, we cannot see the source code on internal arrays to be able to advise on how they work internally.

        You can experiment with using an array, if it's not working as intended you'll need to debug it using prints. For C# arrays, you'll need to use external C# education.

        For custom series values, this might be due to the fact you are not using MaximumBarsLookBack.Infinite lookback on the series. Additionally, you've also synced them to different BarsArrays which will have different slots - you will not be able to access that correctly unless the additional series are all the exact same series.



        Additionally, it seems you may have already posted this same inquiry on the forum already:



        We kindly ask that users refrain from posting multiple threads about the same topic. If you have an existing inquiry you'd like to keep investigating, please reply to the representative you were working with on the original thread. Create a new thread when you would like to start a new, unrelated inquiry. We thank you for your cooperation and understanding.

        Comment


          #5
          Gaby,

          Thank you,

          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]) ;

          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:29 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 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