How to get length of enum and item in MQL4/MQL5 ?

 

How to get length of enum and item in MQL4/MQL5 ?

For example, there has an enum definition:

enum ENUM_FRUIT {APPLE, BANANA, GRAPE};

Next, I want to use it in loop:

for (int i = 0; i < length_of_enum; i++) {
  Print(EnumToString(get_enum_item(i)));
} 

How to implement this requirement?

I've searched forum and code base, but didn't get answer.

:-( 

 
Xiangdong Guo:

How to get length of enum and item in MQL4/MQL5 ?

I've searched forum and code base, but didn't get answer.

:-( 

What do you mean with "length of enum"?

Can you provide an example of usage to understand you question - probably enum is not what you are looking for?

 
Carl Schreiber:

What do you mean with "length of enum"?

Can you provide an example of usage to understand you question - probably enum is not what you are looking for?

I updated my question.
 
int ArrayCopyRates(double& dest_array[], string symbol=NULL, int timeframe=0)
Copies rates to the two-dimensional array from chart RateInfo array, where second dimension has 6 elements:
0 - time,
1 - open,
2 - low,
3 - high,
4 - close,
5 - volume.
Note: Usually retrieved array used to pass large blocks of data to the DLL functions.
Parameters
dest_array[] - Reference to the two-dimensional destination numeric array.
symbol - symbol name, by default, current chart symbol name is used.
timeframe - Time frame, by default, the current chart time frame is used. It can be any of Time frame enumeration values.
Sample
double array1[][6];
ArrayCopyRates(array1,"EURUSD", PERIOD_H1);

Print("Current bar ",TimeToStr(array1[0][0]),"Open", array1[0][1]);

From MQL4 ,might be useful

 
Maryann T Emmanuel:
int ArrayCopyRates(double& dest_array[], string symbol=NULL, int timeframe=0)
Copies rates to the two-dimensional array from chart RateInfo array, where second dimension has 6 elements:
0 - time,
1 - open,
2 - low,
3 - high,
4 - close,
5 - volume.
Note: Usually retrieved array used to pass large blocks of data to the DLL functions.
Parameters
dest_array[] - Reference to the two-dimensional destination numeric array.
symbol - symbol name, by default, current chart symbol name is used.
timeframe - Time frame, by default, the current chart time frame is used. It can be any of Time frame enumeration values.
Sample
double array1[][6];
ArrayCopyRates(array1,"EURUSD", PERIOD_H1);

Print("Current bar ",TimeToStr(array1[0][0]),"Open", array1[0][1]);

From MQL4 ,might be useful

Thanks, Maryann.

But it can't solve my question. 

 
Xiangdong Guo:

Thanks, Maryann.

But it can't solve my question. 

What do you mean "length of enum"?
 
Xiangdong Guo:

How to get length of enum and item in MQL4/MQL5 ?

Do you have an dynamic enum? If yes, please show how you change it. If no - why you can't set length_of_enum = 3 in your code - this is static unchangeable var
 
Xiangdong Guo:

How to get length of enum and item in MQL4/MQL5 ?

For example, there has an enum definition:

Next, I want to use it in loop:

How to implement this requirement?

I've searched forum and code base, but didn't get answer.

:-( 

If you want to loop through a list use an array!

An enum is a kind of a variation of #define:

#define APPLE 0   
#define BANANA 1
#define GRAPE  2 
....

Enum is very useful e.g. for input variables!

 
  enum Fruit {Apple,Banana,Heineken};
  int err=0;
  int scan=0;
  string item_name;

  while(err==0)
   {
   item_name=EnumToString(Fruit(scan));
   err=GetLastError();
   if(err==0) Alert(item_name);
   scan++;
   }
thats the closest i got if the length is unknown
 
Lorentzos Roussos:
thats the closest i got if the length is unknown
The length is never unknown and this topic is just resulting from a bad design.
 
Alain Verleyen:
The length is never unknown and this topic is just resulting from a bad design.
Bad design of what 
Reason: