Download MetaTrader 5

How to use friendly labels for enum options in an external parameter ?

To add comments, please log in or register
Wemerson Guimaraes
611
Wemerson Guimaraes  

Olá,

 

How can i do to add friendly labels for enum options?

See my code below, i used 2 external parameters with enum: AppliedPrice and TradeMode. The first uses a language native enum (ENUM_APLIED_PRICE)  e the second uses an enum that i created myself (ENUM_TRADE_MODE). 

extern ENUM_APPLIED_PRICE AppliedPrice = PRICE_CLOSE;

enum ENUM_TRADE_MODE{ AGGRESSIVE_MODE, MODERATE_MODE, SAFE_MODE };
extern ENUM_TRADE_MODE TradeMode = MODERATE_MODE;


Now, take a look at the 2 elements on the image below. The ENUM_APLIED_PRICE( AppliedPrice) do not shows its declared enum options(PRICE_CLOSE, PRICE_OPEN, etc) but "friendly" text labels instead. But my custom enum (ENUM_TRADE_MODE) shows its optins (AGGRESSIVE_MODE, MODERATE_MODE, SAFE_MODE):

Enums 

 

How can i do to show friendly texts just like native enums? I've tried some options but not works:

...
// First try, but not works
enum ENUM_TRADE_MODE{ AGGRESSIVE_MODE = "Chuck Norris", MODERATE_MODE = "Gentle Gentleman", SAFE_MODE = "Fluffy Puppy" };

// Then i try, but still not works
enum ENUM_TRADE_MODE{ AGGRESSIVE_MODE "Chuck Norris", MODERATE_MODE "Gentle Gentleman", SAFE_MODE "Fluffy Puppy" };
...
whroeder1
15924
whroeder1  
enum ENUM_TRADE_MODE{ AGGRESSIVE_MODE, // Chuck Norris
                      MODERATE_MODE,   // Gentle Gentleman
                      SAFE_MODE};      // Fluffy Puppy
Wemerson Guimaraes
611
Wemerson Guimaraes  
WHRoeder:

No way... it's so simple...

Just a small adjustment because the last element not works on your code... 

enum ENUM_TRADE_MODE{ AGGRESSIVE_MODE, // Chuck Norris
                     MODERATE_MODE, // Gentle Gentleman
                     SAFE_MODE // Fluffy Puppy
                     };

 

Thans man... this was great!... i will never think in use comments

Fab
6
Fab  

Blast from the past here, sorry!

May I ask any of the mql developers why for the hell this feature is not documented e.g. into https://docs.mql4.com/basis/types/integer/enumeration?

This would be quite useful and can save some time to people... (reference manuals should do, right?).

Thank you so much in ada

Enumerations - Integer Types - Data Types - Language Basics - MQL4 Reference
Enumerations - Integer Types - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Enumerations - Integer Types - Data Types - Language Basics - MQL4 Reference
Alain Verleyen
Moderator
33349
Alain Verleyen  
To add comments, please log in or register