Declaration of Array Error message from compile MT4build 600

 

Hello,

i have compile my EA in the new MT4 editor and i get from him a error message for this lines:

     static string Cy[0];
     static string Newv[0];
     static int Tf[0];

The error message that i get is '[' - invalid index value

Have there somethink change complite in the new MT4 Ediotr or language, what is wrong in the array declaration that i use?

 
PlanandTrade:

Hello,

i have compile my EA in the new MT4 editor and i get from him a error message for this lines:

The error message that i get is '[' - invalid index value

Have there somethink change complite in the new MT4 Ediotr or language, what is wrong in the array declaration that i use?

That makes no sense to declare an array with 0 element.
 
PlanandTrade:

Hello,

i have compile my EA in the new MT4 editor and i get from him a error message for this lines:

The error message that i get is '[' - invalid index value

Have there somethink change complite in the new MT4 Ediotr or language, what is wrong in the array declaration that i use?

Yes . . . do this instead . . .
     static string Cy[];
     static string Newv[];
     static int Tf[];
 
angevoyageur:
That makes no sense to declare an array with 0 element.
It does . . . I have done it in the past for arrays that I am always going to resize . . . for example, I used such an array in a function for a Spread MA.
 
RaptorUK:
It does . . . I have done it in the past for arrays that I am always going to resize . . . for example, I used such an array in a function for a Spread MA.

Sorry but I don't understand your point. As you stated in your above post, if you need to resize an array then used a dynamic array.
 
angevoyageur:
Sorry but I don't understand your point. As you stated in your above post, if you need to resize an array then used a dynamic array.

The idea of Dynamic arrays doesn't exist in mql4 . . . what is the size of an array declared thus ?

string Cy[];
 
RaptorUK:

The idea of Dynamic arrays doesn't exist in mql4 . . . what is the size of an array declared thus ?

Ok, I see. But it seems there is now dynamic arrays, and this is why the compiler protest about [0].
 
angevoyageur:
Ok, I see. But it seems there is now dynamic arrays, and this is why the compiler protest about [0].

Yes, of course . . . but if . . .

string Cy[];

// and

string Cy[0];

. . are the same it might have been a good idea to allow 0 as an initial size of the array to help with backwards compatibility. . . . but it wasn't, so we are where we are.

 
PlanandTrade:

Hello,

i have compile my EA in the new MT4 editor and i get from him a error message for this lines:

The error message that i get is '[' - invalid index value

Have there somethink change complite in the new MT4 Ediotr or language, what is wrong in the array declaration that i use?


In MQL4/MQL5 you can't declare an array with 0 index. However, you can declare a dynamic array that you can resize later in your code.

Example:

string Cy[];

int OnInit()
{
  ...

  ArrayResize(Cy,50);
 
  ...
}


You can also declare and initialize a static dynamic array as follow.

Example 2:

static string Cy[] = {"aa","bb","cc"};
 
Thank you, i have also slove it with changing the Array Index at the declaration to 1.
 

Hi,

Hi personnaly used that, before resizing with the numbers of pairs selected by the trader :

double atd_AtrMarge[][][][];


and i get the same compiler message :

'[' - invalid index value


???

Reason: