MQL4 - automated forex trading   /  

Documentation

MQL4 Reference  Array functions  ArrayCopySeries

 
int ArrayCopySeries( void array[], int series_index, string symbol=NULL, int timeframe=0)
Copies a series array to another one and returns the count of the copied elements.

There is no real memory allocation for data array and nothing is copied. When such an array is accessed, the access is redirected. Excluded are arrays that are assigned as indexed ones in custom indicators. In this case, data are really copied.

If data are copied from another chart with different symbol and/or timeframe, it is possible that the necessary data will lack. In this case, error ERR_HISTORY_WILL_UPDATED (4066 - requested history data under updating) will be placed into the last_error variable, and there will be necessary to retry copying after a certain period of time.

Note: If series_index is MODE_TIME, the array to be passed to the function must be of the datetime type.
Parameters:
array[]   -   Reference to the destination one-dimensional numeric array.
series_index   -   Series array identifier. It must be one of series array listed identifiers values.
symbol   -   Symbol name (the name of the currency pair)
timeframe   -   Timeframe of the chart. It can be any of Timeframe list values.
Sample:
datetime daytimes[];
int      shift=10,dayshift,error;
//---- the Time[] array was sroted in the descending order
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
error=GetLastError();
if(error==4066)
  {
   //---- make two more attempts to read
   for(int i=0;i<2; i++)
     {
      Sleep(5000);
      ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
      //---- check the current daily bar time
      datetime last_day=daytimes[0];
      if(Year()==TimeYear(last_day) && Month()==TimeMonth(last_day) && Day()==TimeDay(last_day)) break;
     }
  }
if(Time[shift]>=daytimes[0]) dayshift=0;
else
  {
   dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
   if(Period()<PERIOD_D1) dayshift++;
  }
Print(TimeToStr(Time[shift])," corresponds to ",dayshift," day bar opened at ", TimeToStr(daytimes[dayshift]));