Why does ENUM_APPLIED_PRICE start at 1, instead of 0?

 

After getting some trouble reading custom indicators that use the enum "ENUM_APPLIED_PRICE" I noticed that its first value (PRICE_CLOSE) was 1, instead of 0 as usual.

In MQL4 the documentation especifies its values from 0 to 6, but in MQL5 they aren't explicit.

void OnStart()

{

   for (int i=0; i<=8; i++)
      Print("i = ", i, " ", EnumToString((ENUM_APPLIED_PRICE)i));

}



Is there any reason for that?

Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL4 Reference
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL4 Reference
 
Does it matter?
 
Keith Watford:
Does it matter?

It's not anything fatal, but can be very problematic. That's like asking if timezones matter.

(Especially if all other built-in enums like ENUM_MA_METHOD or ENUM_APPLIED_VOLUME do follow the rule and start at 0)

 
Manuel Alejandro Cercos Perez :

After getting some trouble reading custom indicators that use the enum "ENUM_APPLIED_PRICE" I noticed that its first value (PRICE_CLOSE) was 1, instead of 0 as usual.

In MQL4 the documentation especifies its values from 0 to 6 , but in MQL5 they aren't explicit .

void OnStart()

{

   for (int i=0; i<=8; i++)
      Print("i = ", i, " ", EnumToString((ENUM_APPLIED_PRICE)i));

}



Is there any reason for that?

This is why you should always refer to by name and not by value. At any time, the numbering inside the structure can be changed and you will burn out badly in the fall. But those who refer to the structure by name will not have any problems.

 
Keith Watford:
Does it matter?

Hi Keith,  it does under some circumstances where you cannot use the enumerator, like when applying to a combobox, so you then have to write a translation peice of code. The inconsistency between mql4 and mql5 on this is clearly an oversite and ideally would be corrected, but last time I mentioned it I got all the usual defensive responses of not a bug, does not matter etc.  but the idea of an enum is to avoid translation code and make things easier to understand, and the point of having a unified mql4/5 compiler is for compatability... things like this just become a pain to discover and work around and don't fulfil those ideals.

That said if they just shut MT4 down then it wouldn't be a problem anymore :)

 
Paul Anscombe :

Hi Keith,  it does under some circumstances where you cannot use the enumerator, like when applying to a combobox, so you then have to write a translation peice of code. The inconsistency between mql4 and mql5 on this is clearly an oversite and ideally would be corrected, but last time I mentioned it I got all the usual defensive responses of not a bug, does not matter etc.  but the idea of an enum is to avoid translation code and make things easier to understand, and the point of having a unified mql4/5 compiler is for compatability... things like this just become a pain to discover and work around and don't fulfil those ideals.

That said if they just shut MT4 down then it wouldn't be a problem anymore :)

There is no problem - as people work with MQL5, and the old terminal was thrown out long ago.

 
Vladimir Karputov:

There is no problem - as people work with MQL5, and the old terminal was thrown out long ago.

I wish...
 
Vladimir Karputov:

This is why you should always refer to by name and not by value. At any time, the numbering inside the structure can be changed and you will burn out badly in the fall. But those who refer to the structure by name will not have any problems.

That's true, and ideally when using a concrete indicator in an expert advisor is preferable, but I usually test multiple indicators and going into the specifics of each one would take me much more time (I won't go much into that)


At any time, the numbering inside the structure can be changed

This is my biggest concern, that any enum could just be changed without any reason. It's pretty impractical from a programming point of view...

 
Manuel Alejandro Cercos Perez :

***

This is my biggest concern, that any enum could just be changed without any reason. It's pretty impractical from a programming point of view...

Personally, I would do this on purpose - to teach people like you to refer to ENUM by name, and not by value :)

This is your problem - you are not working correctly with ENUM. As a rule, such mistakes are made by those who are sitting at the old terminal. As soon as you throw the old terminal in the trash, you will begin to program better.

 
Vladimir Karputov:

Personally, I would do this on purpose - to teach people like you to refer to ENUM by name, and not by value :)

This is your problem - you are not working correctly with ENUM. As a rule, such mistakes are made by those who are sitting at the old terminal. As soon as you throw the old terminal in the trash, you will begin to program better.

Then MQL5 developers should consider adding a parameter "enum_applied_price_value" to the MqlParam struct :) (And a TYPE_APPLIED_PRICE to ENUM_DATATYPE)...

Documentación para MQL5: Constantes, Enumeraciones y Estruturas / Estructuras de datos / Estructura de parámetros de entrada de indicador
Documentación para MQL5: Constantes, Enumeraciones y Estruturas / Estructuras de datos / Estructura de parámetros de entrada de indicador
  • www.mql5.com
Estructura de parámetros de entrada de indicador - Estructuras de datos - Constantes, Enumeraciones y Estruturas - Manual de referencia de MQL5 - manual de usuario para el lenguaje del trading algorítmico/automático para MetaTrader 5
Reason: