MQL5 Syntax question?

 

Hi All,

I have a small issue that's puzzling me. When I compile I get a warning about this line being 'implicit enum conversion'

ENUM_ORDER_TYPE cur_type = OrderGetInteger(ORDER_TYPE);

to fix it I have done this:

ENUM_ORDER_TYPE cur_type = (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);

But this seems inelegant, what should I be doing here?

Thanks,

Noki0100

 
Hi, yes there is an alternative - you can use the enumeration as an identifier for the type, instead of getting the int of it and working with the integer
 
Stanislav Ivanov:
Hi, yes there is an alternative - you can use the enumeration as an identifier for the type, instead of getting the int of it and working with the integer

True, Even the way he did is sill fine though it might look improper but it gets the work done.

 

OrderGetInteger is a generic function returning a long. You must cast it to the appropriate type depending on the thing requested: a long, datetime, ENUM_ORDER_TYPE, ENUM_ORDER_STATE, etc. The cast is appropriate.

What you should do to make it "look right" is to encapsulate the data typing thus:

datetime         OrderGetExpiration(void){ return         (datetime)OrderGetInteger(ORDER_TIME_EXPIRATION); }
ENUM_ORDER_TYPE  OrderGetOrderType(void){  return  (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);            }
ENUM_ORDER_STATE OrderGetOrderState(void){ return (ENUM_ORDER_STATE)OrderGetInteger(ORDER_STATE          ); }
⋮
/////////////// 
ENUM_ORDER_TYPE cur_type = OrderGetOrderType();
datetime        expires  = OrderGetExpiration();
 
OK, thanks for the responses, I wanted to just check.