EX4 to MQ4: How to Recover MQL4 Source Code from an EX4 File
EX4 to MQ4: How to Recover MQL4 Source Code from an EX4 File
If you have an EX4 file but no longer have the original MQ4 source code, you may be wondering whether the program can be recovered and converted back into editable MQL4 code.
This is a common situation for MetaTrader 4 users who have lost an Expert Advisor, custom indicator, script, or automated trading system’s original source.
The important thing to understand is that EX4 to MQ4 is not a normal file conversion. An MQ4 file is source code, while an EX4 file is the compiled executable produced from that source. MetaTrader’s own documentation describes the normal development process as writing MQL4 source and compiling it into an EX4 executable. (MetaTrader 4)
So, what happens when you need to go in the opposite direction?
What Is the Difference Between MQ4 and EX4?
The easiest way to understand the difference is to look at the development process:
MQ4 source code → MetaEditor → Compilation → EX4 executable
The MQ4 file is intended to be read and edited by a developer.
The EX4 file is the compiled program that MetaTrader 4 loads and executes.
MetaEditor is designed for creating, editing, and compiling MQL4 source code. (MetaTrader 4)
Once the source has been compiled, the resulting EX4 does not simply contain the original MQ4 text waiting to be opened again.
This is why recovering source code from an EX4 is considerably more complicated than changing:
program.ex4
to:
program.mq4
Renaming the extension does not restore the source code.
What Is EX4 to MQ4 Source-Code Recovery?
EX4 to MQ4 source-code recovery refers to analyzing a compiled EX4 program and attempting to reconstruct usable MQL4 source code from the information available in the executable.
The objective can be different depending on the project.
For example, you may want to:
- Recover a lost Expert Advisor
- Restore an old MT4 indicator
- Modify an existing trading system
- Repair an old project
- Understand how an application works
- Rebuild a discontinued MT4 program
- Maintain software that you own
The final result should be considered reconstructed source code, rather than automatically assuming it will be an exact copy of the developer’s original MQ4.
Can Every EX4 File Be Recovered?
No.
There is no universal guarantee that every EX4 can be converted into an identical MQ4 source file.
The difficulty can depend on:
- The MT4 build associated with the file
- How the program was compiled
- The complexity of the application
- Protection mechanisms
- Obfuscation
- External libraries
- DLL dependencies
- File integrity
- Licensing systems
- Other external resources
MetaQuotes has also documented increased protection for newer MQL4 applications, which is one reason modern EX4 files should not be treated like simple text-based source files. (MQL4 Reference)
Step 1: Identify What Type of EX4 You Have
Before considering source-code recovery, determine what the file actually is.
An EX4 may represent:
Expert Advisor
An EA can contain automated trading logic, order management, risk calculations, entry and exit conditions, and other trading functions.
Custom Indicator
An indicator processes market data and can display calculations, signals, lines, arrows, or other chart objects.
Script
A script is generally designed to perform a specific action rather than continuously manage trades.
The type of program can affect how the recovered source needs to be analyzed and tested.
Step 2: Check for Related Files
The EX4 may not be the only component of the application.
Look for related:
- DLL files
- EX4 libraries
- MQH files
- Configuration files
- Presets
- Images
- Data files
MQL4 supports external libraries, including DLLs and compiled EX4 libraries, through external function declarations and imports. (MQL4 Reference)
This is particularly important when dealing with sophisticated Expert Advisors.
Why DLL Dependencies Matter
Suppose an EA depends on an external DLL:
MT4 EA → EX4 → DLL → External Function
The EX4 may call functions that are implemented outside the MQL4 program itself.
If the DLL is unavailable, encrypted, protected, or licensed, recovering the MQL4 portion may not be sufficient to reproduce the complete original functionality.
This is why a source-recovery assessment should identify external dependencies before promising a particular result.
Step 3: Determine the Original MT4 Environment
The MT4 build and compilation history can be relevant when assessing an EX4.
Older and newer MQL4 environments have undergone significant changes, including changes to file structure and application protection. (MQL4 Reference)
If possible, document:
- MT4 version
- MT4 build
- Approximate date the EA was created
- Broker or terminal where it originally operated
- Whether DLL imports were enabled
- Whether additional files were required
This information can help provide context for the recovery process.
Step 4: Analyze the EX4
The next stage is technical analysis of the compiled file.
The purpose is to determine what information can potentially be reconstructed and whether the file contains unusual protection or dependencies.
This stage is important because two EX4 files can have completely different technical characteristics.
A simple indicator may present a very different challenge from a sophisticated automated trading system containing multiple external components.
Step 5: Reconstruct the MQL4 Source
If recovery is technically feasible and legally authorized, the available program information can be used to reconstruct an MQ4 project.
The resulting source may require additional development work.
For example, it may need:
- Function reconstruction
- Variable reconstruction
- Compilation fixes
- Logic cleanup
- Dependency restoration
- Input reconstruction
- Indicator-buffer reconstruction
- Manual coding
The objective is to produce usable source code rather than merely generate a file with an .mq4 extension.
Why the Recovered MQ4 May Not Look Like the Original
One of the biggest misconceptions about EX4 decompilation is that the output will necessarily look exactly like the developer’s original source.
That should not be assumed.
The original programmer may have used:
Meaningful variable names
Detailed comments
Custom formatting
Specific function organization
Include files
Development notes
Some source-level information may not be preserved in the compiled executable.
The recovered project can therefore require manual cleanup and reconstruction before it becomes convenient to maintain.
Step 6: Compile the Recovered MQ4
After reconstruction, the MQ4 source should be opened in MetaEditor and compiled.
The normal MQL4 development workflow is to compile source code into an EX4 executable. (MetaTrader 4)
Compilation can reveal problems such as:
- Syntax errors
- Missing functions
- Incorrect declarations
- Missing include files
- External-library problems
- Incorrect parameters
- Compatibility issues
A recovered source file that simply opens in a text editor is not necessarily a successful recovery.
Compilation and testing are important parts of the process.
Step 7: Compare the Recovered Program With the Original
If the original EX4 still works, it can serve as a reference for testing.
For an Expert Advisor, compare important behavior such as:
- Entry signals
- Exit signals
- Stop-loss calculations
- Take-profit calculations
- Lot sizing
- Trade filters
- Magic numbers
- Trading times
- Risk controls
For an indicator, compare:
- Indicator values
- Signals
- Alerts
- Chart objects
- Timeframe behavior
- Historical calculations
The objective is to determine whether the reconstructed source behaves consistently with the original application.
What About Copy-Trading EAs?
Copy-trading Expert Advisors can require additional investigation.
A typical system may look like:
Master Account → Trade Signal → Communication Layer → Receiver EA → Trade Execution
The communication layer could involve files, network services, external libraries, or other mechanisms.
If the original MQ4 source is lost, recovering the EA may require identifying how it:
- Detects trades
- Filters trades
- Transfers information
- Calculates lot sizes
- Maps symbols
- Handles stop-loss and take-profit
- Executes receiver orders
If a DLL is part of the system, that dependency should be identified before assuming the entire copy-trading system can be reconstructed from the EX4 alone.
What About DLL-Encrypted EX4 Files?
DLL-protected or encrypted components can make a source-recovery project substantially more complicated.
An EA may depend on a DLL for functionality such as:
- External calculations
- Licensing
- Authentication
- Data processing
- Communication
- Security functions
If the DLL cannot be analyzed or is unavailable, some functionality may remain dependent on that external component.
In such cases, the realistic outcome may be:
MQ4 source recovered + external dependency remains
rather than:
Complete original system recovered perfectly
This distinction is important when evaluating an EX4 recovery project.
What Should You Provide for an EX4 Recovery Assessment?
If you own the software or have permission to analyze it, providing additional information can make the assessment more useful.
Ideally, keep:
The original EX4
Do not modify the original file unnecessarily.
Related DLL files
If the EA uses external libraries, preserve the corresponding files.
Other EX4 libraries
MQL4 can use compiled EX4 libraries as external modules. (MQL4 Reference)
MQH or old source fragments
Even an incomplete backup can provide useful information.
Screenshots
Screenshots of the EA or indicator operating in MT4 can help establish expected functionality.
Configuration files
Presets and other configuration files may be useful during testing.
How Long Does EX4 to MQ4 Recovery Take?
There is no single time frame that applies to every EX4.
A simple file and a complex protected trading system are very different projects.
The amount of work can depend on:
- File complexity
- Protection
- External dependencies
- DLL requirements
- Testing requirements
- Amount of manual reconstruction
- Whether the original behavior can be reproduced
For this reason, it is better to assess the actual EX4 before promising a fixed result.
Is EX4 to MQ4 the Same as a Normal Converter?
No.
A normal converter transforms data from one supported format into another.
For example:
CSV → XLSX
is a format conversion.
EX4 → MQ4 is fundamentally different because one is compiled executable code and the other is source code.
The process is therefore better described as:
EX4 analysis → source reconstruction → MQ4 development → compilation → testing
Protecting Your Own MQ4 Source Code
If you are an MQL4 developer, the best solution is to avoid losing your source code in the first place.
Keep secure backups of:
- MQ4 files
- MQH include files
- DLL dependencies
- EX4 builds
- Presets
- Documentation
- Project notes
MetaTrader’s file structure includes dedicated locations for Experts, Indicators, Scripts, Include files, Libraries, Files, and other resources. (MetaTrader 4)
Having a complete project backup is significantly easier than trying to reconstruct a lost source file years later.
Final Thoughts
An EX4 to MQ4 decompiler can be relevant when the original MQL4 source code has been lost, but EX4 source recovery is not a guaranteed one-click conversion.
The technical situation can vary considerably from one file to another.
An EX4 may be relatively straightforward to assess, while another may contain sophisticated protection, copy-trading functionality, external EX4 libraries, or DLL dependencies.
If the software is yours or you have authorization to analyze it, the best starting point is to preserve the original EX4 and all associated files, identify the program’s dependencies, and assess what can realistically be reconstructed.
The goal should ultimately be more than producing an MQ4 file.
The goal is to recover a usable, compilable, testable, and maintainable MQL4 project.