Download MetaTrader 5
To add comments, please log in or register
Create interesting Forum topics concerning the automated trading!
marksimmonds
18
marksimmonds 2016.01.11 11:53 

Hi,

I'm trying to create objects by looping through an array...... here's the code, but when I try to compile, I get the error "  '[' - invalid index error  "

Can somebody confirm if it can be done, and what I'm doing wrong

Thanks in advance.

//---Create Array of Symbols we wish to interogate
string Instruments[30] = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CADJPY", "CHFJPY",
                      "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURTRY", "EURUSD",
                      "GBPAUD", "GBPCAD", "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDCAD", "NZDCHF",
                      "NZDJPY", "NZDUSD", "USDCAD", "USDCHF", "USDJPY", "USDTRY"};
                      
//---CREATE CLASS STRUCTURE FOR SIGNALS

class PriceAction
  {
public:
   string name;
 };

for(int i=0; i < ArraySize(Instruments); i++)
     {
      PriceAction Instruments[i]();
      //Alert("New Object created:", Symbols[i].name);
     }
Ovo Cz
2950
Ovo Cz 2016.01.11 12:06  
Did you noticed you have Instruments declared twice? The second declaration is invalid, and moreover its live cycle is only within the current block.
whroeder1
13619
whroeder1 2016.01.11 13:11  
  1. Ovo: Did you noticed you have Instruments declared twice? The second declaration is invalid, and moreover its live cycle is only within the current block.
    If you had used #property strict, the compiler would have warned you about that.

  2. To create an array of objects the object must have a default constructor. See Structures and Classes - MQL4 Documentation. This you have since you didn't declare any constructors.
  3. You must do any other initialization in a method.

/
To add comments, please log in or register