Download MetaTrader 5
To add comments, please log in or register
Traders have already contributed more than 300 articles. Write your own one!
Byung Ho Lee
19
Byung Ho Lee 2013.02.05 02:35 

I would like to cutting the array to keep fresh 1,000 elements and discard old 1,000 elements. The following code works in MT4, but it seems not to be work in MT5.

Is there any method? Thanks.

//if the array size more than 2,000, then decrease array size to 1,000
int ArrayCutting()
{
   int size_limit=2000,size_new=1000;
   int size=ArraySize(m_wavePr_pt);
   
   if(size>size_limit)
   {
      ArraySetAsSeries(m_wavePr_pt,true);
      
      ArrayResize(m_wavePr_pt,size_new);
      
      ArraySetAsSeries(m_wavePr_pt,false);
   }
   return(0);
}
phi nuts
2184
phi nuts 2013.02.05 04:17  
remoton:

I would like to cutting the array to keep fresh 1,000 elements and discard old 1,000 elements. The following code works in MT4, but it seems not to be work in MT5.

Is there any method? Thanks.


If the resize does not works, then find out what error did you get and read the doc about ArrayResize , there you can read that you have to declare your array as a dynamic array.

And you don't have to set - reset the array to timeseries just to resize it.  

if (ArrayResize (my_arr, 100)) == -1)
   {
   Print (GetLastError());
   }


Byung Ho Lee
19
Byung Ho Lee 2013.02.05 04:43  
phi.nuts:

If the resize does notworks, then find out what ArrayResize do, there you can read that you have to declare your array as a dynamic array.

And you don't have to set - reset the array to timeseries.  

 

Thanks, phi.nuts.

The array declared as dynamic array. In MT4, above code keeps the last added 1,000 elements after ArrayResize(...) statement. But in MT5, after ArrayResize(...) statement, there is old elements in the array and newly added elements deleted. Anyway, forget the code. Is there any method to keep the last added elements  when contracting the array?

Ahmed Soliman
12295
Ahmed Soliman 2013.02.05 05:35  

Why don't you use ArrayCopy to temp array then re-cooy to your original one?
Byung Ho Lee
19
Byung Ho Lee 2013.02.05 05:51  
codersguru:

Why don't you use ArrayCopy to temp array then re-cooy to your original one?

Many thanks codersguru,

solved :

 

int ArrayCutting()
{
   int size_limit=2000,size_new=1000;
   int size=ArraySize(m_wavePr_pt);
   double   tempPr[];
   
   if(size>size_limit)
   {
      ArrayCopy(tempPr,m_wavePr_pt,0,size_new+1,size_new);
      ArrayResize(m_wavePr_pt,size_new);
      ArrayCopy(m_wavePr_pt,tempPr,0,0,size_new);
   }
   return(0);
}
Ahmed Soliman
12295
Ahmed Soliman 2013.02.05 05:55  
remoton:

Many thanks codersguru,

solved :

 

You're welcome!
/
To add comments, please log in or register