EX4 Decompiler: How EX4 Decompilation and Source-Code Recovery Works
An EX4 decompiler is generally associated with the process of analyzing a compiled MetaTrader 4 program when the original MQL4 source code is no longer available.
Understanding what happens during EX4 decompilation requires first understanding the difference between an MQ4 source file and an EX4 compiled file.
An MQ4 file contains MQL4 source code that developers can read and modify. When that source code is compiled, MetaEditor produces an EX4 executable that can be loaded and run by MetaTrader 4. MetaQuotes documentation and MQL4 community documentation describe EX4 as the compiled form intended for execution rather than normal source-code editing. (MQL5)
When the original MQ4 file has been lost, source-code recovery may involve analyzing the available EX4 program, identifying its structure and dependencies, reconstructing appropriate MQL4 code where possible, and then compiling and testing the resulting source.
However, EX4 source recovery is not the same thing as simply converting one file extension into another, and the result is not necessarily identical to the original developer’s source code.
What Is an EX4 File?
An EX4 file is the compiled form of an MQL4 program.
A typical development process looks like this:
MQ4 source code → MetaEditor compiler → EX4 executable
The MQ4 source is designed for development and modification. The resulting EX4 is designed to be executed by MetaTrader 4.
This distinction is important because changing:
program.ex4
to:
program.mq4
does not restore the source code.
The contents of the file are compiled rather than ordinary human-readable MQL4 source.
MetaEditor is used to compile MQL programs, producing executable files from their corresponding source files. (MQL5)
What Does an EX4 Decompiler Actually Mean?
The term EX4 decompiler is commonly used to describe software or a technical process intended to analyze a compiled EX4 program and attempt to reconstruct information about the original source.
It is useful to separate three different concepts:
- Compilation
- Decompilation
- Source-code reconstruction
Compilation
Compilation starts with readable source code.
For example:
EA.mq4
is processed by the compiler and becomes:
EA.ex4
The compiler transforms the source into an executable representation that MetaTrader can run.
Decompilation
Decompilation attempts to work in the opposite direction:
EA.ex4 → reconstructed representation
This does not necessarily mean the original MQ4 file is recreated exactly.
Compiled programs generally contain information optimized for execution rather than for preserving the developer’s original formatting, comments, organization, and naming.
Source-Code Reconstruction
Source-code reconstruction is often a more useful description of the practical goal.
The objective may be to produce an MQ4 project that reproduces the important behavior of the available EX4 program and can be maintained or modified.
The reconstructed source may therefore be structurally different from the original source while still implementing similar functionality.
Why Can’t You Simply Open an EX4 in MetaEditor?
MetaEditor is designed around source-code development.
With normal MQL4 development, the developer opens an MQ4 file, modifies the source, and compiles it to create an EX4 file.
An EX4 distributed without its MQ4 source is intended to run as a compiled program. MQL4 documentation and community explanations specifically distinguish MQ4 source from EX4 compiled programs and note that normal modification requires the source file. (MQL5)
This creates an important situation:
If you have MQ4:
You can normally edit the source and compile it again.
If you only have EX4:
You do not have the original editable source project.
That is where source-code recovery becomes relevant.
How EX4 Source-Code Recovery Works
A legitimate source-recovery project can involve several stages.
1. File Assessment
The first step is determining what you actually have.
For example:
- EX4 Expert Advisor
- EX4 custom indicator
- EX4 script
- EX4 library
- Multiple EX4 files
- MQH include files
- DLL files
- Configuration files
- Presets
- Documentation
- Original project backups
The more supporting material available, the easier it may be to understand the program’s architecture.
2. Identify the Program’s Role
An EX4 filename alone does not necessarily tell you whether the program is an Expert Advisor, indicator, or script.
The surrounding MT4 directory structure and how the program behaves can provide useful information.
For example, an EA may interact with:
- Market prices
- Orders
- Positions
- Indicators
- Risk-management rules
- Trading sessions
- External libraries
- DLL functions
Understanding the program’s role helps establish what needs to be reconstructed.
3. Analyze Program Structure
A technical recovery process may examine the available compiled program for information that helps reveal its architecture.
The goal is not simply to produce random MQL4 text.
A useful recovery project attempts to understand things such as:
- Program entry points
- Functions
- Inputs
- Variables
- Trading operations
- Indicator calculations
- Control flow
- External dependencies
- Imported functions
- File operations
- Error handling
- Trading conditions
The exact amount of information available depends heavily on the particular EX4 file and how it was produced.
4. Map Dependencies
Many MT4 programs do not operate as completely isolated files.
An EA may depend on:
- EX4 libraries
- DLL files
- MQH/MQ4 include files
- External indicators
- Configuration files
- Presets
- Data files
- Broker-specific settings
For this reason, analyzing only one EX4 file may not provide the complete picture.
A source-recovery assessment should identify important dependencies before attempting to reconstruct the project.
EX4 Files and DLL Dependencies
DLLs deserve special attention.
An EX4 program may call external functions rather than performing every operation internally.
This can affect source-code recovery because the EX4 does not necessarily contain the implementation of every external function it uses.
For example, an application might contain an interface to an external DLL while the actual functionality resides inside that DLL.
Therefore, recovering the EX4’s MQL4-side logic does not automatically recreate the external DLL’s source code.
A complete assessment should distinguish between:
MQL4 logic inside the EX4
and
external functionality supplied by another component.
Copy-Trading EAs and EX4 Recovery
Copy-trading Expert Advisors can be more complicated than simple trading scripts because they may contain several components.
A copy-trading system could involve:
- Master-account communication
- Receiver-account logic
- Trade detection
- Symbol mapping
- Lot-size calculations
- Risk multipliers
- Order synchronization
- Magic numbers
- Filtering rules
- DLL communication
- External servers
- Licensing systems
If the original MQ4 source is lost, understanding these components can be important before attempting reconstruction.
The objective should be to identify what the EX4 actually depends on rather than assuming that every feature exists entirely inside one compiled file.
What Information Can Be Recovered?
The answer depends on the individual EX4.
A recovery project may be able to reconstruct or document aspects such as:
- Inputs and parameters
- Program structure
- Trading operations
- Indicator calculations
- Conditions
- Functions
- Variables
- Risk-management logic
- Order-management logic
- External calls
- General control flow
But recovery should never be presented as a guarantee that the original source will be reproduced character-for-character.
The original developer may have used:
- Comments
- Specific variable names
- Particular formatting
- Multiple MQH files
- External libraries
- External DLLs
- Build-specific features
- Proprietary development tools
Some of that information may not be available from the compiled program alone.
Can an EX4 Be Converted Back Into the Original MQ4?
This is one of the most important questions.
Not necessarily.
There is a major difference between:
Recovering usable source code
and:
Recovering the exact original source project.
Even when source reconstruction is technically possible, the resulting MQ4 may differ from the original source in:
- Variable names
- Comments
- Formatting
- Function organization
- File structure
- Internal implementation
- Optimization
- Supporting files
The practical goal may therefore be functional reconstruction rather than exact historical reproduction.
Why MT4 Build History Matters
MetaTrader 4 has gone through major changes over its lifetime.
Build 600 and later introduced substantial changes to the MQL4 development environment and compiler architecture. MetaQuotes also documented changes to the MQL4 language, MetaEditor, program protection, and EX4/EX5 formats around that transition.
This means that the age and compiler generation of an EX4 can be relevant when evaluating an old file.
For example, an older EX4 may have been produced using a substantially different development environment than a newer EX4.
Therefore, an EX4 recovery assessment should consider the file’s history whenever that information is available.
Build 509 vs. Build 600+
Build 509 is frequently mentioned in discussions about historical MQL4 programs.
Build 600 introduced a significantly revised MQL4 environment and compiler.
MetaQuotes documented that older programs could continue to operate after the transition and that existing EX4 files were not automatically recompiled simply because the terminal was upgraded. (MQL5)
For source recovery, this history matters because an old EX4 should not automatically be treated as if it were produced by the current MQL4 toolchain.
What About Protected EX4 Files?
Protection is another major consideration.
Modern MQL4 executable files are not simply plain-text source files with an EX4 extension. The platform’s compiler and protection mechanisms are specifically designed to make compiled programs suitable for distribution without providing the original source.
There are also long-running community discussions about EX4 decompilation, especially following the Build 600 changes. Some forum moderators have stated that there has been no demonstrated general-purpose recovery of modern protected EX4/EX5 programs, while other community posts make different claims. These are community statements rather than a guarantee about any particular file. (MQL5)
For this reason, a professional recovery assessment should examine the actual file rather than promise a result before inspection.
What Cannot Normally Be Assumed From an EX4?
An EX4 file should not automatically be assumed to contain:
- The original MQ4 formatting
- Original comments
- Original variable names
- Original project structure
- Every external dependency
- DLL source code
- Server-side code
- Original documentation
- Original development environment
The compiled program may provide useful information about its behavior, but that does not mean every part of the development project is recoverable.
EX4 Decompilation vs. Redevelopment
Sometimes the better technical approach is not traditional decompilation.
Instead, a developer may use the available EX4 as a behavioral reference and recreate the required functionality in a new MQ4 project.
For example, if an old EA is no longer maintainable but its behavior is understood, a redevelopment project could focus on reproducing:
- Entry rules
- Exit rules
- Risk management
- Position sizing
- Indicator conditions
- Trading filters
- Session restrictions
- Order management
This can produce a maintainable MQ4 project without claiming that it is the original source.
For many practical maintenance projects, this distinction is important.
A Typical EX4 Source-Recovery Workflow
A professional workflow can be organized into the following stages:
Stage 1 — Collect the Files
Gather:
- EX4 files
- MQ4 files, if any
- MQH files
- DLLs
- Presets
- Configuration files
- Supporting indicators
- Libraries
- Documentation
Stage 2 — Inspect the Environment
Determine:
- MT4 version
- Available files
- Program type
- Dependencies
- Historical build information
- Whether the EX4 still runs
Stage 3 — Analyze the EX4
Study the available executable and identify relevant program structures and behavior.
Stage 4 — Map Dependencies
Determine whether the application depends on:
- DLLs
- EX4 libraries
- External indicators
- Files
- Servers
- Other components
Stage 5 — Reconstruct Source
Where technically and legally appropriate, reconstruct the MQL4 project required for maintenance or modification.
Stage 6 — Compile
The reconstructed MQ4 should be compiled using the appropriate MQL4 development environment.
Stage 7 — Test
The resulting EX4 should be tested against the original program wherever possible.
Stage 8 — Compare Behavior
Compare important functionality such as:
- Inputs
- Signals
- Orders
- Stops
- Take profits
- Lot calculations
- Alerts
- Indicator output
- Risk controls
A successful compilation alone does not prove that the recovered program behaves correctly.
Why Compilation Is Not Enough
An MQ4 file can compile successfully while still behaving differently from the original EX4.
For example, a recovered program could contain:
- Incorrect trading conditions
- Different lot calculations
- Missing dependency behavior
- Incorrect symbol handling
- Different indicator values
- Different timing behavior
- Incorrect order-management logic
Therefore, functional testing is a critical part of source-code recovery.
The normal MQL development process treats compilation as the creation of an executable; testing is a separate concern. (MQL5)
How to Test Recovered MQ4 Source
Testing should ideally happen in a controlled environment before live trading.
Useful checks include:
Compilation Testing
Confirm that the reconstructed source compiles without critical errors.
Strategy Tester
Compare historical behavior where the original EX4 can also be tested.
Demo Account Testing
Run the recovered EA on a demo account and compare its behavior with the original.
Parameter Testing
Check whether:
- Inputs behave correctly
- Risk settings work
- Lot sizing is consistent
- Stop-loss values are correct
- Take-profit values are correct
Trade Execution Testing
Check:
- Buy orders
- Sell orders
- Modifications
- Closures
- Pending orders
- Error handling
Dependency Testing
If the program relies on DLLs, libraries, files, or external services, verify those components separately.
Original EX4 vs. Recovered MQ4
A useful way to evaluate recovery is to compare functionality rather than simply comparing source-code appearance.
|
Area |
Original EX4 |
Recovered MQ4 |
|
Executable format |
EX4 |
MQ4 source that can be compiled |
|
Human-readable source |
No |
Yes, if successfully reconstructed |
|
Original comments |
May not be available |
May need to be recreated |
|
Original variable names |
May not be preserved |
May be reconstructed differently |
|
Dependencies |
Must be identified |
Should be documented |
|
Modification |
Not normally performed like MQ4 |
Can be edited after recovery |
|
Testing |
Can be tested in MT4 |
Should be compiled and tested |
|
Exact original project |
Not guaranteed |
Not guaranteed |
When Should You Consider EX4 Source Recovery?
Source recovery may be worth investigating when:
- The original MQ4 file has been lost
- You own the EA or have authorization to analyze it
- The original developer is unavailable
- You need to maintain an older MT4 program
- You need to modify an existing EA
- You need to migrate or rebuild functionality
- You need to understand dependencies
- You have the EX4 but no editable source
If the original MQ4 source is available, however, recovering it from the EX4 is generally unnecessary. The original source is the better starting point for modifications.
Questions to Ask Before Using an EX4 Recovery Service
Before submitting an EX4, ask:
- Do you assess the EX4 before starting?
- Do you distinguish source recovery from redevelopment?
- Can you identify external DLL dependencies?
- Can you work with older MT4 files?
- Do you provide a compilable MQ4 project where possible?
- Is functional testing included?
- How are dependencies handled?
- Do you explain limitations before beginning?
- How is the submitted file handled?
- Do you require proof that I own or am authorized to analyze the software?
These questions help separate a technical recovery project from a simple claim that an EX4 can always be converted into its original MQ4.
Is EX4 Decompilation Always Possible?
No.
The feasibility depends on the particular program.
Important variables can include:
- EX4 generation
- Compiler history
- Protection
- Program complexity
- Dependencies
- DLL usage
- External services
- Availability of supporting files
- Desired level of source reconstruction
A responsible technical assessment should therefore avoid promising that every EX4 can be recovered perfectly.
EX4 Decompiler: Frequently Asked Questions
What is an EX4 decompiler?
An EX4 decompiler generally refers to a tool or process intended to analyze a compiled MetaTrader 4 EX4 program and potentially reconstruct information about its underlying MQL4 logic.
Can I edit an EX4 directly?
An EX4 is a compiled program rather than the normal editable MQL4 source. For ordinary development, changes are made to MQ4 source and then compiled into EX4. (MQL5)
Can EX4 be converted to MQ4?
Source-code reconstruction may be possible in some circumstances, but it should not be described as a guaranteed conversion into the exact original MQ4 project.
Will the recovered MQ4 be identical to the original?
Not necessarily. Comments, formatting, names, project organization, dependencies, and implementation details may not be recoverable.
Does every EX4 contain its complete source code?
No. An executable should not be treated as a copy of the original MQ4 project.
What if my EA uses a DLL?
The DLL should be treated as a separate dependency. Recovering MQL4-side code does not automatically recover the DLL’s original source code.
Does MT4 Build 600 matter?
Yes. Build 600 introduced significant changes to the MQL4 language, compiler and development environment, making build history relevant when evaluating older programs.
Should I test recovered source code?
Yes. Compilation is only one step. The resulting EA or indicator should be tested carefully before being used in a live trading environment.
Can an EX4 decompiler recover an EA perfectly?
There is no universal guarantee. The result depends on the particular EX4, its generation, protection, dependencies and the information available for reconstruction.
Final Takeaway
An EX4 decompiler should not be thought of as a simple file converter.
The normal MT4 development process moves from:
MQ4 source → compiler → EX4 executable
When the source is lost, the reverse problem becomes substantially more complicated.
A legitimate EX4 source-code recovery project can involve file assessment, program analysis, dependency mapping, source reconstruction, compilation and functional testing. The objective may be to recover maintainable MQL4 functionality rather than reproduce every character of the original developer’s source.
If you own the software or have permission to analyze it, the most useful first step is to collect the EX4 and any related MQH, DLL, library, preset and configuration files. Those supporting files can be just as important as the EX4 itself.
Most importantly, recovered source should be treated as a new development artifact until it has been compiled, tested and compared against the original program’s behavior.