Migrating from MQL4 to MQL5 - Problem 3!

To add comments, please log in or register
Carl Schreiber
Moderator
7238
Carl Schreiber  

From MQL4 I took and adapted myDefs.mqh e.g. this function that returns the order type in a unified text form:

string pos2txt ( ENUM_ORDER_TYPE pos ) {     // pos2txt(aPosOpnPOS[idx])
        switch (pos) {
                case ORDER_TYPE_BUY               :  return("BUY ");
                case ORDER_TYPE_SELL              :  return("SELL");
                case ORDER_TYPE_BUY_LIMIT         :  return("BuLi");
                case ORDER_TYPE_SELL_LIMIT        :  return("SeLi");
                case ORDER_TYPE_BUY_STOP          :  return("BuSt");
                case ORDER_TYPE_SELL_STOP         :  return("SeSt");
                case ORDER_TYPE_BUY_STOP_LIMIT    :  return("BuSL"); // line 3263, at 11 i s the O of ORDER_TYPE_BUY_STOP_LIMIT
                case ORDER_TYPE_SELL_STOP_LIMIT   :  return("SeSL"); // line 3264, at 11 i s the O of ORDER_TYPE_SELL_STOP_LIMIT
                case ORDER_TYPE_CLOSE_BY          :  return("ClBy"); // line 3265, at 11 i s the O of ORDER_TYPE_CLOSE_BY
                default                           :  return("N.O.");
        }
}

Again myDefs.mqh compiles with no error!!
But as soon as an indicator loads this file and is compiled the compiler grumbles:

'ORDER_TYPE_BUY_STOP_LIMIT' - undeclared identifier     myDefs.mqh      3263    11
'ORDER_TYPE_BUY_STOP_LIMIT' - constant expression required      myDefs.mqh      3263    11
'ORDER_TYPE_SELL_STOP_LIMIT' - undeclared identifier    myDefs.mqh      3264    11
'ORDER_TYPE_SELL_STOP_LIMIT' - constant expression required     myDefs.mqh      3264    11
'ORDER_TYPE_CLOSE_BY' - undeclared identifier   myDefs.mqh      3265    11
'ORDER_TYPE_CLOSE_BY' - constant expression required    myDefs.mqh      3265    11

Of course I have checked, copied and pasted them from the reference to have no typo??

So

  1. Why does myDefs.mqh compiles without any error, but if an indicator loading this file without using this functions?
  2. Why it accepts the other 6 but not the last three?
Alain Verleyen
36553
Alain Verleyen  
Seems you are again compiling this as mql4 code, while ..._STOP_LIMIT only exist in mql5.
Carl Schreiber
Moderator
7238
Carl Schreiber  
Alain Verleyen:
Seems you are again compiling this as mql4 code, while ..._STOP_LIMIT only exist in mql5.

AGAIN - I am using the editor for MQL5!!

Just look at the first problem. It won't compile for MQL4 - convinced?

Alain Verleyen
36553
Alain Verleyen  
Carl Schreiber:

AGAIN - I am using the editor for MQL5!!

Just look at the first problem. It won't compile for MQL4 - convinced?

Quite stubborn huh ?

mq4 file is mql4 code.

Carl Schreiber
Moderator
7238
Carl Schreiber  
As I wrote elsewhere, the MQL5 editor saves mq4 files when compiled as mq4 instead of mq5 file - that is what I was not expecting!
To add comments, please log in or register