CreateObject To Display The Value of an enum? - page 3

 
onewithzachy: check the 6th parameter of iMA (https://docs.mql4.com/en/indicators/ima). It is integer, and not some enum type.
Check that link a little further down:
applied_price
[in] Applied price. It can be any of ENUM_APPLIED_PRICE enumeration values.
 
WHRoeder:
Check that link a little further down:
applied_price
[in] Applied price. It can be any of ENUM_APPLIED_PRICE enumeration values.

So next question will be, what is the member of any ENUM_APPLIED_PRICE ? Is it in form of integer ? The answer is yes, it is an integer.


 
Aren't you guys taking this way seriously ?
 

enums have an integer value.

either of these is acceptable

iMA(NULL,0,14,0,MODE_EMA,PRICE_HIGH,0); // using one of the ENUM_APPLIED_PRICE enums

iMA(NULL,0,14,0,MODE_EMA,2,0);          // using the integer value of the PRICE_HIGH enum

my point was about the user defined enum which also have the same integer value.

#property strict
enum Prices // user inputs to be only close, open, high, low so ENUM_APPLIED_PRICE not suitable
{
CLOSE,
OPEN,
HIGH, 
LOW
};
input Prices PRICE = HIGH;
//-----
void OnStart()
  {
   double val = iMA(NULL,0,14,0,MODE_EMA,PRICE,0);
  }

Compiler: 'PRICE' - improper enumerator cannot be used

compiler rejects my user defined PRICE enum. Which also has the same value as PRICE_HIGH enum and the integer value 2 and IMO should be accepted by the compiler as a correct parameter in iMA().

The workaround is to copy the value from the enum to an integer and then use that integer as the parameter. That seems like extra code for no good reason and defeats the object of enumerating the constants in the first place.

 

OK I posted to the service desk about this, in case anyone is interested the support team told me how to do it, by using explict cast:

#property strict
enum Prices // user inputs to be only close, open, high, low so ENUM_APPLIED_PRICE not suitable
{
CLOSE,
OPEN,
HIGH, 
LOW
};
input Prices PRICE = HIGH;
//-----
void OnStart()
  {
   double val = iMA(NULL,0,14,0,MODE_EMA,(ENUM_APPLIED_PRICE)PRICE,0);
  }
 
This assumes the ordering in ENUM_APPLIED_PRICE matches your enum.
enum Prices // user inputs to be only close, open, high, low so ENUM_APPLIED_PRICE not suitable
{
CLOSE,
OPEN,
HIGH,
LOW
Drop OPEN for example, the code breaks: (ENUM_APPLIED_PRICE)PRICE when PRICE=LOW becomes PRICE_HIGH. Try and find that bug!
Make sure they're always in sync:
enum Prices // user inputs to be only close, open, high, low so ENUM_APPLIED_PRICE not suitable
{
CLOSE = PRICE_CLOSE,
OPEN = PRICE_OPEN,
HIGH = PRICE_HIGH,
LOW = PRICE_LOW
 

Yes for sure, the integer values of the enums have to be the same as the predefined ones. You can assign the values explicitly like you did by enum or by the correct integer value. For the debugging reason you mentioned it is probably best to always do this even if the default sequential enumeration would assign the correct values.

#property strict
enum Prices // user inputs to be only close, open, typical, weighted so ENUM_APPLIED_PRICE not suitable
{
CLOSE = 0,  //using integer values to match the APPLIED_PRICE enums
OPEN = 1,
TYPICAL = 5, 
WEIGHTED = 6,
};
input Prices PRICE = TYPICAL;
//-----
void OnStart()
  {
   double val = iMA(NULL,0,14,0,MODE_EMA,(ENUM_APPLIED_PRICE)PRICE,0);
   Alert(val);
  }
 
SDC:

Yes for sure, the integer values of the enums have to be the same as the predefined ones. You can assign the values explicitly like you did by enum or by the correect integer value. For the debugging reason you mentioned it is probably best to always do this even if the default sequential enumeration would assign the correct values.

#property strict
enum Prices // user inputs to be only close, open, typical, weighted so ENUM_APPLIED_PRICE not suitable
{
CLOSE = 0,  //using integer values to match the APPLIED_PRICE enums
OPEN = 1,
TYPICAL = 5, 
WEIGHTED = 6,
};
input Prices PRICE = TYPICAL;
//-----
void OnStart()
  {
   double val = iMA(NULL,0,14,0,MODE_EMA,(ENUM_APPLIED_PRICE)PRICE,0);
   Alert(val);
  }

I'm sure you know, but that comment on the CLOSE = 0 line will change how that appears in the dropdown list.

 
Yes you can use your own comment to make it a user friendly description of the input in the dropdown list.
Reason: