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

 
WHRoeder:
Why create a new one that is identical to an existing one? You can't use yours with TimeDayOfWeek unless you write conversion routines between your days and enum_day_of_week. Etc.
Obviously at the time we didnt know there was already an existing one.
 
Either way, all are good. XD
 
WHRoeder:
Why create a new one that is identical to an existing one? You can't use yours with TimeDayOfWeek unless you write conversion routines between your days and enum_day_of_week. Etc.

I dont understand what you mean by that, correct me if I am wrong but all enums are identifiers to integer values right ? So how is there any difference between user created enums and predefined ones ?

 

Is this what you mean ?

for example the user needs to chose from only Close, Open, High, Low prices and not any of the others so the predifined ENUM_APPLIED_PRICE is not suitable.

#property strict
enum Prices
{
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

The enum has a correct integer value yet the enum is not allowed UNLESS it is the predefined APPLIED_PRICE enum. What is the point of this error ?

So now take the value from the enum and put it in a regular integer instead ....

#property strict
enum Prices
{
CLOSE,
OPEN,
HIGH, 
LOW
};
input Prices PRICE = HIGH;
//-----
void OnStart()
  {
   int price = PRICE;
   double val = iMA(NULL,0,14,0,MODE_EMA,price,0);
  }

//+------------------------------------------------------------------+

Compiler: 0 error(s), 0 warning(s)

Now the value is in an integer the compiler allows it, the compiler error is not logical.

 
Sorry for the confusion, the enum days was just an example. EnumToString was exactly what I was looking for. thank you!
 
SDC:

Is this what you mean ?

for example the user needs to chose from only Close, Open, High, Low prices and not any of the others so the predifined ENUM_APPLIED_PRICE is not suitable.

Compiler: 'PRICE' - improper enumerator cannot be used

The enum has a correct integer value yet the enum is not allowed UNLESS it is the predefined APPLIED_PRICE enum. What is the point of this error ?

So now take the value from the enum and put it in a regular integer instead ....

Compiler: 0 error(s), 0 warning(s)

Now the value is in an integer the compiler allows it, the compiler error is not logical.


Or by converting it to integer, will give no error ...

double val = iMA(NULL,0,14,0,MODE_EMA,(int)PRICE,0);

The reason for compiler error in your code is that because 6th parameter of iMA must be an integer and should not be other than integer.

In your code, variable/data type of "Prices" is enum and not integer. That's why compiler say "I can't use other than integer for 6th parameter of iMA". Hence the err.


 
onewithzachy:

The reason for compiler error in your code is that because 6th parameter of iMA must be an integer and should not be other than integer.

No, it must be enumeration and should not the other than enumeration.

The word is that casting int->enum is implemented, while enum->enum throws error.

 
DeepThought:

No, it must be enumeration and should not the other than enumeration.

The word is that casting int->enum is implemented, while enum->enum throws error.


Please click and check the 6th parameter of iMA (https://docs.mql4.com/en/indicators/ima).

It is integer, and not some enum type.

Assign integer to some enum type is OK, though it will give compiler a warning.


 
onewithzachy:

Please click and check the 6th parameter of iMA (https://docs.mql4.com/en/indicators/ima).

It is integer, and not some enum type.

Assign integer to some enum type is OK, though it will give compiler a warning.




The compiler does not know the site you linked. It still demands enumeration.


 
DeepThought:


The compiler does not know the site you linked. It still demands enumeration.



Wow, use MQL documentation instead some ME pop-out, please.

Read again the link I gave (https://docs.mql4.com/en/indicators/ima, click that please), the 6th parameter of iMA function needs integer parameter.

For 6th parameter of iMA, we can use any member of ENUM_APPLIED_PRICE - click that please - which its members are integer value. ENUM_APPLIED_PRICE is a built-in enum inside MQL4 for price constant, so when we using ENUM_APPLIED_PRICE, the compiler will typecast it immediately and give no warning.

Since on code above we're not using any member of ENUM_APPLIED_PRICE, but we use our own enum, we have to typecast it to integer.