MQL4 Reference Array Functions ArrayCopyRates


Copies rates data to the array and returns the amount of bars copied. There are 2 variants of the function:

int  ArrayCopyRates(
   MqlRates&  rates_array[],   // MqlRates array, passed by reference
   string     symbol=NULL,     // symbol
   int        timeframe=0      // timeframe

Copies rates data to the RateInfo[][6] two-dimensional array of double type and returns the amount of bars copied.

int  ArrayCopyRates(
   void&     dest_array[][],    // destination array, passed by reference
   string    symbol=NULL,       // symbol
   int       timeframe=0        // timeframe



[out]  Destination array of MqlRates type.


[out]  Two-dimensional destination array of double type.


[in]  Symbol name.


[in]  Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.

Returned value

The function returns copied bars amount, or -1 if failed.

If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 - the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).


This rates array is normally used to pass data to a DLL function.

In the first variant of the function it performs the virtual data copying to the array of MqlRates type. It means that if timeseries data has been updated, rates_array[] array always will refer to the actual data.

In the second variant it performs the real data copying to dest_array[][] array. The destination array will be resized to the size of the timeseries (even if the destination array has been declared as static).

First dimension of RateInfo array contains bars amount, second dimension has 6 elements:

0 - time,
1 - open,
2 - low,
3 - high,
4 - close,
5 - volume.


#property copyright "Copyright © 2013, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"
#property strict
#property description "Expert Advisor displaying two cases of"
#property description "ArrayCopyRates() function call"
//--- destination array for physical copying of historical data
double   double_array[][6];
//--- destination array for logical copying of historical data
MqlRates mqlrates_array[];
//--- first call flag
bool first_call;
//| Expert initialization function                                   |
int OnInit()
//--- run this EA at chart with M1 timeframe
     Alert("The Expert Advisor must be attached to M1 chart!");
//--- first call
//--- all ok
//| Expert deinitialization function                                 |
void OnDeinit(const int reason)
//--- delete all comments
//| Expert tick function                                             |
void OnTick()
      //--- copying physically  double_array
      //--- virtual copying -> mqlrates_array will contain the reference on the data
      //--- cancel first call flag
   //--- at each tick print the values of the 0-th array element to see the difference
   Comment("The values of double_array[] are not changed (because of real data copying):\n",
           "0 - time: ",(datetime)double_array[0][0],"\n",
           "1 - open: ",double_array[0][1],"\n"
           "2 - low: ",double_array[0][2],"\n"
           "3 - high: ",double_array[0][3],"\n"
           "4 - close: ",double_array[0][4],"\n"
           "5 - volume: ",DoubleToString(double_array[0][5],0),"\n\n",
           "The values of mqlrates_array[] are changed (because of virtual data copying):\n",
           "0 - time: ",mqlrates_array[0].time,"\n",
           "1 - open: ",mqlrates_array[0].open,"\n"
           "2 - low: ",mqlrates_array[0].low,"\n"
           "3 - high: ",mqlrates_array[0].high,"\n"
           "4 - close: ",mqlrates_array[0].close,"\n"
           "5 - volume: ",mqlrates_array[0].tick_volume);