EX4 Decompilation Explained: Process, Limitations and What to Expect
EX4 Decompilation Explained: Process, Limitations and What to Expect
If you have an EX4 file but no longer have the original MQ4 source code, you may have heard about EX4 decompilation or EX4 to MQ4 source-code recovery.
But what does EX4 decompilation actually involve?
Can an EX4 file really be turned back into MQ4?
What happens during the process, and what should you realistically expect from the recovered source code?
This guide explains the process in simple terms, including the major limitations, DLL dependencies, copy-trading systems, testing requirements, and factors that can affect the final result.
What Is EX4 Decompilation?
EX4 decompilation refers to the process of attempting to reconstruct usable MQL4 source code from a compiled EX4 program.
In the normal development process, a developer creates an MQ4 source file and compiles it using MetaEditor. The resulting EX4 file is the compiled program used by MetaTrader 4.
The normal direction is:
MQ4 → Compilation → EX4
EX4 decompilation attempts to work in the opposite direction:
EX4 → Recovery/Reconstruction → MQ4
However, this is not the same as a standard file conversion.
An EX4 is compiled code, while MQ4 is source code. MetaTrader documentation and related MQL4 materials distinguish between source files and compiled EX4 programs. (MQL5)
Why Do People Need EX4 Decompilation?
There are several legitimate reasons someone may need to recover MQL4 source code.
For example, a developer may have lost the original project after:
- A computer failure
- Accidental deletion
- A missing backup
- A hard-drive failure
- Migration to another computer
- Loss of an old development environment
- Inheritance of an older trading system
A user may also need source code to maintain or modify an old Expert Advisor that is available only as an EX4.
In these situations, source-code recovery can potentially restore the ability to inspect, maintain, or rebuild a program.
EX4 Decompilation Is Not the Same as Renaming a File
One of the biggest misconceptions is that an EX4 file can be converted simply by changing its extension.
For example:
MyEA.ex4
cannot be turned into source code by renaming it:
MyEA.mq4
The contents remain compiled program data.
Similarly, opening an EX4 in a normal text editor will not reveal the original MQL4 source.
The EX4 format is intended to be executed by MetaTrader 4, while MQ4 is the source-code format used during development.
How Does the EX4 Decompilation Process Work?
The exact techniques used for source recovery can vary depending on the particular file.
At a high level, the process can involve several stages.
1. Initial File Assessment
The first step is to examine the EX4 file itself.
This can help determine:
- Whether the file is complete
- Its general characteristics
- Potential compatibility issues
- Whether external dependencies may be involved
- Whether additional files should be provided
This initial assessment is important because not every EX4 file presents the same recovery challenge.
2. Compatibility Analysis
The compilation environment can matter.
MetaTrader 4 has gone through significant changes over its lifetime. MetaQuotes documented major MQL4 and terminal changes around Build 600 and later, including changes to the MQL4 data structure and compiler environment. (MQL5)
Older and newer EX4 programs may therefore behave differently during analysis and testing.
3. Program Structure Recovery
The next stage is attempting to recover useful program structures from the compiled file.
Depending on the individual EX4, this may involve reconstructing elements associated with:
- Functions
- Variables
- Conditions
- Calculations
- Trading operations
- Inputs
- Indicator logic
- Program flow
The goal is to produce usable MQL4 source rather than simply extracting random information from the file.
4. Source Reconstruction
Recovered information may need to be reconstructed into a readable MQ4 structure.
This is where the difference between the original source and recovered source becomes important.
The recovered code may not preserve the exact formatting, comments, variable names, or organization used by the original developer.
5. Compilation
Once usable MQ4 source has been reconstructed, it can be compiled in MetaEditor.
Compilation can reveal:
- Syntax errors
- Missing functions
- Missing dependencies
- Compatibility issues
- Incorrect declarations
- Other problems requiring repair
6. Functional Testing
Compilation alone is not enough.
An Expert Advisor that compiles successfully should still be tested to determine whether it behaves as expected.
For trading software, testing can include:
- Strategy Tester testing
- Historical comparison
- Demo-account testing
- Indicator-output comparison
- Order-management testing
- Risk-management testing
How Accurate Is EX4 Decompilation?
This is one of the most important questions.
There is no universal guarantee that recovered MQ4 will be identical to the original source code.
Compilation can remove or transform information that existed at the source-code level.
The original developer may have used:
- Meaningful variable names
- Detailed comments
- Specific formatting
- Development notes
- Internal organization
- Separate source files
- Include files
- Libraries
Some of this information may not be recoverable exactly.
Therefore, a successful recovery should generally be viewed as source reconstruction, not necessarily a perfect restoration of the original development project.
What Can Potentially Be Recovered?
Depending on the particular EX4, recovery may provide useful elements such as:
- Trading conditions
- Entry rules
- Exit rules
- Stop-loss logic
- Take-profit logic
- Indicator calculations
- Risk-management functions
- Position-management logic
- Input parameters
- Time filters
- Symbol restrictions
- Trading filters
- External function references
The exact amount of recoverable information depends on the individual file.
Why Some EX4 Files Are More Difficult Than Others
There is no single difficulty level for EX4 files.
File Age
Older EX4 files and newer EX4 files may have different characteristics because the MQL4 development environment has evolved.
Program Complexity
A small indicator can be much easier to understand than a large Expert Advisor containing numerous strategies and modules.
Protection
Protection mechanisms can make source reconstruction substantially more difficult.
Obfuscation
Some developers deliberately make their software structure harder to analyze.
External Dependencies
An EX4 may depend on external libraries, DLLs, files, or other compiled components.
File Damage
If the EX4 is incomplete or corrupted, recovery may be affected.
DLL Dependencies and EX4 Decompilation
DLLs deserve special attention.
MQL programs can interact with external DLL modules through imported functions. MetaTrader documentation describes external modules as separate from the compiled MQL program. (MQL5)
This means an EX4 may contain calls to functionality that actually exists outside the EX4.
For example:
EX4 → DLL → External Function
Recovering the EX4’s MQL4 portion does not automatically reproduce the code contained inside the DLL.
If an Expert Advisor depends on DLLs, it is therefore useful to preserve the complete set of files originally distributed with the program.
MetaQuotes also warns users to consider the risks of running unknown EX4 programs that import external DLL functions. (MQL5)
What About Copy-Trading EX4 Programs?
Copy-trading systems can be more complicated because they may consist of multiple components.
A typical architecture might look like:
Master EA → Communication Layer → Receiver EA → Trading Account
The communication layer could involve:
- Files
- Network communication
- DLLs
- EX4 libraries
- External servers
- Other software
Therefore, recovering one EX4 does not necessarily recreate the complete copy-trading system.
If you are working with a copy-trading EA, preserve the entire software package whenever possible.
EX4 Libraries Can Also Matter
An Expert Advisor may use compiled libraries rather than containing every function directly inside its main EX4.
MetaTrader’s MQL4 environment supports compiled EX4 libraries in the MQL4 Libraries directory. (MQL5)
This means a complete recovery project may require more than the main EA file.
Useful supporting files can include:
- EX4 libraries
- DLLs
- MQH files
- Configuration files
- Preset files
- Data files
- Other indicators
- Additional EAs
What Should You Provide for EX4 Source Recovery?
If you are authorized to recover the program, providing the complete original package can make analysis easier.
Ideally, preserve:
1. Original EX4
Do not modify the original file.
2. DLL files
Include any DLLs that came with the software.
3. Supporting EX4 libraries
These may contain functionality required by the main program.
4. Configuration files
Some systems rely on external settings.
5. Preset files
These can help reproduce the original operating environment.
6. Previous versions
An older version may sometimes provide useful information if the latest file has problems.
What Happens If the Recovered MQ4 Does Not Compile?
This does not necessarily mean the recovery failed.
Recovered code may require manual repair.
For example, problems could involve:
- Missing declarations
- Incorrect function definitions
- Missing libraries
- External dependencies
- Compiler compatibility
- Structural inconsistencies
The recovered source may therefore need to go through a repair and compilation stage.
What Happens If It Compiles but Trades Differently?
This is an important distinction.
A program can compile successfully but still behave differently from the original.
For example, differences could appear in:
- Entry timing
- Exit timing
- Indicator values
- Order placement
- Lot calculations
- Stop-loss placement
- Take-profit placement
- Trade filters
That is why behavioral testing is an essential part of the process.
How Should Recovered EX4 Source Be Tested?
A sensible testing process is:
Step 1: Compile the Recovered MQ4
Check for compilation errors and warnings.
Step 2: Run Historical Tests
Compare important results with the original EX4 where possible.
Step 3: Test on a Demo Account
Observe the program under live market conditions without immediately risking real capital.
Step 4: Compare Trading Behavior
Compare entries, exits, position sizes, and other important functions.
Step 5: Test Dependencies
Make sure DLLs, libraries, and other required components work correctly.
Common EX4 Decompilation Misconceptions
“Every EX4 can be perfectly decompiled.”
Not necessarily.
Different EX4 files have different levels of complexity and protection.
“EX4 is just encrypted MQ4.”
Not exactly.
EX4 is compiled program output, not simply an MQ4 file with a different extension.
“Changing EX4 to MQ4 will restore the source.”
No.
Changing the filename extension does not reconstruct source code.
“If the recovered MQ4 compiles, it must be identical.”
No.
Compilation proves that the source is syntactically acceptable to the compiler. It does not prove that every behavior is identical to the original program.
“Recovering the EX4 automatically recovers its DLL.”
No.
An external DLL is a separate module and may contain functionality outside the MQL4 program. (MQL5)
How Long Does EX4 Decompilation Take?
There is no single answer.
A relatively straightforward file may require less work than a complex Expert Advisor with:
- Multiple modules
- External DLLs
- Compiled libraries
- Licensing systems
- Complex trading logic
- Protection mechanisms
The condition of the file also matters.
For this reason, it is better to evaluate the individual EX4 rather than promise a fixed recovery time before examining it.
Is EX4 Decompilation Legal?
The answer depends on ownership, authorization, licensing terms, and applicable law.
If you created the software, lost your own MQ4 source, or have permission from the copyright owner to recover it, source-code recovery may be a legitimate maintenance or restoration activity.
However, possessing an EX4 does not automatically grant permission to reverse engineer, reproduce, modify, or redistribute proprietary software.
Always make sure you have the appropriate rights before attempting source recovery.
EX4 Decompilation vs. Rebuilding an EA
These are also different processes.
EX4 decompilation/source recovery attempts to reconstruct source from an existing compiled program.
EA rebuilding means recreating the trading system based on available information, such as:
- Trading behavior
- Screenshots
- Strategy descriptions
- Parameters
- Backtest results
- Observed entries and exits
If the original source cannot be recovered adequately, rebuilding may be another technical option—but it is not the same as recovering the original source.
What Should You Expect From a Professional EX4 Recovery Service?
A responsible service should not promise that every EX4 will produce a perfect copy of the original MQ4.
Instead, the process should acknowledge the possibility of:
- Partial recovery
- Code reconstruction
- Manual repair
- Missing dependencies
- DLL complications
- Compilation issues
- Behavioral differences
- Incompatibility
A good assessment should focus on the specific EX4 file rather than making a blanket guarantee.
Final Thoughts
EX4 decompilation is best understood as a source-code recovery and reconstruction process, not a simple file conversion.
The normal development process goes from MQ4 source code to a compiled EX4 program. Recovering source works in the opposite direction and can be affected by compiler history, protection, program complexity, external libraries, DLLs, and file condition.
Even when useful MQ4 code can be recovered, it may require additional repair, compilation, and testing before it is ready for practical use.
If you have lost the original MQL4 project and are authorized to recover it, preserve the original EX4 and all supporting files before beginning. Most importantly, evaluate the individual file realistically rather than assuming that every EX4 can produce an identical copy of the original source.