Resizing timeseries in EA

 

Hi All,

I am trying to include my indicator within my EA but am facing some issues with timeserie arrays. I have created arrays and set them as timeserie but when resizing this is still adding new elements to the end of the array, I was expecting when resizing a timeserie to have new elements added to the front of the array?


double ar[]; // Array
ArrayResize(ar,2); // Prepare the array
ar[0]=1; // Set the values
ar[1]=2; 
ArraySetAsSeries(ar,true); // Change the indexing order
ArrayResize(ar,3); // Increase the array size
ar[0]=3; // Set the value for the new array element
Alert(ar[0]," ",ar[1]," ",ar[2]); // Print array values


Above code example gives me output 3 , 1, 0 where I am expecting 3, 2, 1. Am I missing something here?


Thnx

 

lucaskoster:

I am trying to include my indicator within my EA 

Above code example gives me output 3 , 1, 0 where I am expecting 3, 2, 1. Am I missing something here?

  1. Don't try to do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)

    Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.

  2. Normally, set your indexing direction before you initialize the array.
    Code
     [0]  [1] [2]
    Non-series=default;Resize(2);ar[0]=1;ar[1]=2
    1
    2
    Does not exist
    AsSeries
    2
    1
    Does not exist
    Resize(3)
    2
    1
    random
    ar[0]=3
    3
    1
    random

    What I think what you are trying to do is make a stack (insert new zero, shift rest). On MT4:

    template <typename Datatype>
           bool    resize_buffer(Datatype& deque[],       ///<[in,out] The deque.
                                 COUNT     nRows){
       // This enlarges the arr and shifts values B[2]=B[1]; B[1]=B[0]; B[0]=prob 0.
       bool     isSeries = ArrayGetAsSeries(deque);
       ArraySetAsSeries(deque, !isSeries);
       if(ArrayResize(deque, nRows) <= 0)           return false;
       ArraySetAsSeries(deque, isSeries);           return true;
    }
    
Reason: