Adding elements to an Array

 

Hi all,

I am trying to add elements (values of an indicator), tick by tick, to an array. I managed to do it with the following code but I imagine there is a more practical way without all of the shifting. And obviously the code below results in some lagging.


#include <Arrays\ArrayDouble.mqh>
CArrayDouble MA;

void MovingAvg() //Function called under void OnTick()
  {

   MA.Resize(2);
   MA.Shift(2,3);
   MA.Shift(1,2);
   MA.Shift(3,-3);
   MA.Add(MA_Array[0]);

  }


Is there an "array.SetAsSeries()" or something that automatically add and shift values to array[0].

PS: I am not a coder.

Thank you in advance.

 
Jan-HarmZ63:

Hi all,

I am trying to add elements (values of an indicator), tick by tick, to an array. I managed to do it with the following code but I imagine there is a more practical way without all of the shifting. And obviously the code below results in some lagging.



Is there an "array.SetAsSeries()" or something that automatically add and shift values to array[0].

PS: I am not a coder.

Thank you in advance.

Speed depending on how many elements you have.

   string tmpArr[];
   ArrayResize(tmpArr, 4);
   tmpArr[0] = "Button 1";
   tmpArr[1] = "Button 2";
   tmpArr[2] = "Button 3";
   tmpArr[3] = "Button 4";
   ArrayResize(tmpArr, 3);
   ArraySetAsSeries(tmpArr, true);
   ArrayResize(tmpArr, 4);
   tmpArr[ArraySize(tmpArr)-1] = "Button 0";
   ArraySetAsSeries(tmpArr, false);
Reason: