How to force meta editor to compile my class as MQL4

 

Hi...

I have an mql4 class and I have compiled it in meta editor on another pc successfully. But in the other computer, I keep getting errors like "'OP_BUY' - undeclared identifier" or "'Ask' - undeclared identifier".

It seems that the editor tries to compile my file with mql5 compiler. How could I fix it?

How meta editor determines proper compiler for an "mqh" file?


 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. You installed MQL5 not MQL4. See terminal → Help → About
  3. Download and install MQL4.
  4. It doesn't. It has only one compiler; the one you downloaded.

If you used this , you would have found (among 100+) Where to download MT4? - General - MQL5 programming forum 2017.04.31
   How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

It has been years since you could download MT4 from Metaquotes. You can only get it from a broker's website.
          Where to download the orginal MT4 installer - MQL4 programming forum 2018.01.29

Possibly the "clean MT4" download link:
          MT4 download - General - MQL5 programming forum #2

Possibly MetaQuotes' MT4 Installation Link

 
Mohammad Golzar:

Hi...

I have an mql4 class and I have compiled it in meta editor on another pc successfully. But in the other computer, I keep getting errors like "'OP_BUY' - undeclared identifier" or "'Ask' - undeclared identifier".

It seems that the editor tries to compile my file with mql5 compiler. How could I fix it?

How meta editor determines proper compiler for an "mqh" file?


mt5 and mt4 are completely different languages with completely different syntax. so i think its because your trying to use mt5 compiler to compile an mt4 code. like you try to compile a cpp code with a C# or fortran compiler.
for compiling your code successfully try a meta trader 4 distribution ( like mt4 , alpari 4 .etc ) because each mt got the own compiler along with it self.
 
HAMED DANESH:
mt5 and mt4 are completely different languages with completely different syntax. so i think its because your trying to use mt5 compiler to compile an mt4 code. like you try to compile a cpp code with a C# or fortran compiler.
for compiling your code successfully try a meta trader 4 distribution ( like mt4 , alpari 4 .etc ) because each mt got the own compiler along with it self.

Yes. you are correct. I have meta trader 4 that I downloaded from my broker's website and it was ok until I installed meta trader 5 on my system and believe me I knew which version I was using. So after facing this issue, I uninstalled mt5 but it did not help. I uninstalled mt4 and installed it again and the issue still exist.

The funny part is that a file with mq4 extension such as an expert adviser or a script compiles correctly but compiling include files or classes with mqh extension results such errors.

 
Mohammad Golzar: compiling include files or classes with mqh extension results such errors.

You include "include files" into mql4 files. You do not compile them. They are no stand alone files

 
William Roeder #:

You include "include files" into mql4 files. You do not compile them. They are no stand alone files

Wrong. If a file is compiled through the MQL4 Editor it should compile as such and if it is compiled using MQL5 Editor, it should compile using that syntax.

The problem is, that once you compile the file near any class file that is being used for MQL5, it will not compile in MQL4 editor.

I am using common files for both editors, to keep the classes common but the mq4 and mq5 files separate. Now because of this issue, it is not possible to keep one file for both.

If I am using common files, their directory would be external and not internal "include folder". 

Reason: