How to open EX4 file in MetaEditor
Files of such type, as well as MQ4 files, contain program code of Expert Advisors, indicators or scripts, which are executed in MetaTrader environment. The difference between EX4 and MQ4 files is the format of the stored code. In the first case it is a binary executable code, often encrypted. In the second case it is the source code the MQL4 language.
Expert Advisors, indicators and scripts for the MetaTrader 4 terminal are created in the MetaEditor application. Every time the programmer creates a new software product, its source code is saved in the MQ4 file. When the programmer compiles a file (press F7), MetaEditor creates binary code for this software product and saves it in a file with EX4 extension.
To clearly see the differences between the two file types in question, you can try opening them with a simple text viewer. This is what we will see in the MQ4 file:
And here are the contents of the EX4 file:
Obviously, in the second case, we have a completely unreadable code in front of us (if we disregard the header).
Why is this happening?
The language understood by humans (including programming language) is very different from the language understood by a computer. Without going into too much detail, it should only be noted that in English there are 28 letters and 10 digits available to humans. These can be used to form a great many words of varying length. A computer can recognize only two symbols, 0 and 1 and it can form "words" of fixed width, 8 symbols. These words are called bytes.
The set of instructions a modern computer processor can execute is also very limited. There are no classes, properties and methods. There are no functions and not even loops. There are only arithmetic operations, data forwarding commands and conditional and unconditional jumps.
In order to make a program written by a human being understandable to a computer, a conversion from a high-level programming language (which is MQL4) to a low-level language (machine code) is required. This conversion is called a compilation. Compiling changes not only the syntax, but also the logic. More precisely, the logic remains, but it is expressed in a completely different way due to the different set of commands available, which was mentioned above.
For this reason, when looking at machine code, humans are never able to figure it out. EX4 files contain exactly machine (binary) code and cannot be read directly by humans.
So how to open an EX4 file in MetaEditor?
There are two pieces of news — bad news and good news. The bad news is that you cannot open a file with an EX4 extension in the MetaEditor application. This application can only open files with MQ4 extension. The good news is that in most cases the source code can be restored, saved under the same name in MQ4 format and then opened in MetaEditor!
This process is called decompilation. Not long ago (in 2013 and before), this conversion could be done automatically. Special software, called EX4 decompilers, were used for this purpose. This was possible because MetaEditor did not perform the conversion directly to binary code. Instead, so-called bytecode was created, which was compiled on the fly at runtime.
However, all that changed in February 2014. As of build 600, MetaTrader 4 works directly with the machine code, which is created in MetaEditor during compilation. After this build was published, the EX4 decompiler was buried. It turned out to be useless.
For a long time, the problem was unsolvable. Nowadays, a solution has been found. The EX4 files are decompiled online using a special service. The service employs qualified specialists who make the necessary conversions manually, executing the Expert Advisor's code step by step and restoring the logic of the EA's work piece by piece.
So, what do you need to open the EX4 file in MetaEditor? Here is a step-by-step guide:
- Open the request form
- Upload an EX4 file
- Wait for reply from the expert
- Read and accept the offer
- Receive the prepared MQ4 file and save it in MetaTrader data folder
- Open the saved file in MetaEditor
If you still have questions about the EX4 files, you can ask the experts.