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

 
Lorentzos Roussos:
thats the closest i got if the length is unknown

Your approach solved my problem on this issue. Thanks.

 
int index = 0;
while(true)
{
        string enum_string = EnumToString((ENUM_NAME)index);
        if(enum_string  == "ENUM_NAME::"+(string)index)break;
        
        Print(enum_string);
        index++;
}
 

I cleaned up the previous codes in a small and useful function:

template<typename T>
void PrintEnum(T dummy = -1)
  {
   Print(typename(T));
   Print("  {");
   for(int i = -1; i < USHORT_MAX; i++)
      if(StringFind(EnumToString((T)i),"::")<0)
         printf("   %s = %d,",EnumToString((T)i),i);
   Print("  };");
  }

void OnStart()
  {
   PrintEnum<ENUM_TIMEFRAMES>();
   PrintEnum<ENUM_ACCOUNT_INFO_DOUBLE>();
  }


//output
/*
enum ENUM_TIMEFRAMES
  {
   PERIOD_CURRENT = 0,
   PERIOD_M1 = 1,
   PERIOD_M2 = 2,
   PERIOD_M3 = 3,
   PERIOD_M4 = 4,
   PERIOD_M5 = 5,
   PERIOD_M6 = 6,
   PERIOD_M10 = 10,
   PERIOD_M12 = 12,
   PERIOD_M15 = 15,
   PERIOD_M20 = 20,
   PERIOD_M30 = 30,
   PERIOD_H1 = 16385,
   PERIOD_H2 = 16386,
   PERIOD_H3 = 16387,
   PERIOD_H4 = 16388,
   PERIOD_H6 = 16390,
   PERIOD_H8 = 16392,
   PERIOD_H12 = 16396,
   PERIOD_D1 = 16408,
   PERIOD_W1 = 32769,
   PERIOD_MN1 = 49153,
  };
enum ENUM_ACCOUNT_INFO_DOUBLE
  {
   ACCOUNT_BALANCE = 37,
   ACCOUNT_CREDIT = 38,
   ACCOUNT_PROFIT = 39,
   ACCOUNT_EQUITY = 40,
   ACCOUNT_MARGIN = 41,
   ACCOUNT_FREEMARGIN = 42,
   ACCOUNT_MARGIN_LEVEL = 43,
   ACCOUNT_MARGIN_SO_CALL = 45,
   ACCOUNT_MARGIN_SO_SO = 46,
   ACCOUNT_MARGIN_INITIAL = 48,
   ACCOUNT_MARGIN_MAINTENANCE = 49,
   ACCOUNT_ASSETS = 50,
   ACCOUNT_LIABILITIES = 51,
   ACCOUNT_COMMISSION_BLOCKED = 52,
  };
*/