Loop for ArrayCopyRates not working

 

HI,

I want to be able place 9 currency pair rates inside array specified to that pair. Compiles successfully without errors, so there is no syntax errors in the code. But In Terminal when I am launching EA in message window, it shows this kind off error:

2013.08.08 21:22:47     multi_chart GBPUSD,H1: 1 parameter for ArrayCopyRates function must be array

I am using this code.

  double GBPUSD[][6];
    double USDCHF[][6];
      double USDJPY[][6];
        double EURGBP[][6];
          double EURCHF[][6];
            double EURJPY[][6];
              double CHFJPY[][6];
                double USDEUR[][6];
                  double EURUSD[][6];

int init()
  {

  string SymbolPairs[0][9] = {"EURUSD","GBPUSD","USDCHF","USDJPY", "EURGBP", "EURCHF", "EURJPY", "CHFJPY","USDEUR"}; // Iam setting array that holds all Symbol Pairs that I need
  string ArrayNames[0][9] = {"EURUSD","GBPUSD","USDCHF","USDJPY", "EURGBP", "EURCHF", "EURJPY", "CHFJPY","USDEUR"}; // Iam setting array that holds all Array names that I need
  
  for (int a=0;a<=8;a++) // Im starting loop that repeats 9 times, as  times as many Currency Pairs I need
  {
  string array_name = ArrayNames[a][1]; // I am setting variable that holds each time other array name
  string symbol_pairs = SymbolPairs[a][1];// I am setting variable that holds each time other SymbolPair
  
  ArrayCopyRates(array_name, symbol_pairs, PERIOD_D1); // I am doing actual ArrayCopyRates, that each time uses other Array and Currency pair
  }

  return(0);
   
  }

Is there some ideas that causes the problem ?

Thank You!

 
 1 parameter for ArrayCopyRates function must be array

your first parameter is a string, not an array.

 
double GBPUSD[][6];
    double USDCHF[][6];
    :
int init(){
   ArrayCopyRates(GBPUSD, "GBPUSD", PERIOD_D1);
      ArrayCopyRates(USDCHF, "USDCHF", PERIOD_D1);
   :
 
edgars.rworks:

Is there some ideas that causes the problem ?

1. Correct the array declaration and its use and make the loop dynamic by using ArraySize() rather than coding a hard number (such as 9). For example (code not compiled or tested):

string SymbolPairs[] = {"EURUSD", "GBPUSD", "USDCHF", "USDJPY", "EURGBP", "EURCHF", "EURJPY", "CHFJPY", "USDEUR"};  
  
for (int a = 0; a <= ArraySize(SymbolPairs) - 1; a++) 
{
  string array_name = SymbolPairs[a]; 
  string symbol_pairs = SymbolPairs[a];
  
  ...
}

2. ArrayCopyRates() expects an array as its first argument. You are simply supplying it a string, not a variable.

ArrayCopyRates(array_name, symbol_pairs, PERIOD_D1); // I am doing actual ArrayCopyRates, that each time uses other Array and Currency pair

This is the root cause of the error you received. Supply an array as the first argument to ArrayCopyRates(), not a string of characters which you think represents the name of the array.

 
Thirteen:

1. Correct the array declaration and their use and make the loop dynamic by using ArraySize() rather than coding a hard number (such as 9). For example (code not compiled or tested):

2. ArrayCopyRates() expects an array as its first argument. You are simply supplying it a string, not a variable.

This is the root cause of the error you received. Supply an array as the first argument to ArrayCopyRates(), not a string of characters which you think represents the name of the array.


Ok, thanks for answer. I did it. It works.

But how can I retrieve all array in way to see them in alerts ?

I tried such code. But it just retrieves SymbolPair name. But with

array_name[u][] 
 '[' - unexpected token	C:\Program Files (x86)\MetaTrader 4\experts\multi_chart.mq4 (53, 25)    //this is error using code above

Full code for alert

for (int u=0;u <= ArraySize(SymbolPairs) - 1;u++)
       Alert(array_name[u][], symbol_pairs);