Complete Guide to EX4 Decompilation: EX4 to MQ4 Source Code Recovery
Complete Guide to EX4 Decompilation: EX4 to MQ4 Source Code Recovery
If you have an old EX4 file but no longer have the original MQ4 source code, you may be wondering whether the source code can be recovered.
This is where EX4 decompilation and source-code recovery come into consideration.
An EX4 file is the compiled form of an MQL4 program. MQ4 is the editable source-code format used to create Expert Advisors, indicators, scripts, and other MetaTrader 4 applications. MetaQuotes documentation explains that compiling an MQ4 source file produces an EX4 executable file used by the MetaTrader 4 terminal. (MQL5)
This complete guide explains what EX4 decompilation means, how EX4 and MQ4 files are related, what affects source-code recovery, the limitations involved, and what to consider before using an EX4 decompiler.
Important: EX4 source-code recovery should only be performed on software you own or are authorized to analyze. This guide is educational and does not provide instructions for bypassing software protection or extracting protected third-party code.
What Is an EX4 File?
An EX4 file is a compiled MQL4 program designed to run inside MetaTrader 4.
EX4 files can represent different types of MQL4 applications, including:
- Expert Advisors (EAs)
- Custom indicators
- Scripts
- Compiled libraries
The original development file is normally an MQ4 source file. Once the source code is compiled, MetaEditor produces an EX4 file that can be used by MetaTrader 4. (c.mql5.com)
For example:
MQ4 source code → compilation → EX4 executable
The important difference is that MQ4 is intended for editing, while EX4 is intended for execution.
What Is EX4 Decompilation?
EX4 decompilation refers to analyzing a compiled EX4 program in an attempt to recover information that resembles its original source code.
The goal of legitimate source-code recovery is usually to regain the ability to:
- understand an old EA
- maintain legacy software
- repair an existing application
- migrate an old trading system
- recover lost development work
- rebuild functionality from an old compiled program
However, decompilation is not the same as simply converting one file extension into another.
Changing:
example.ex4
to:
example.mq4
does not recreate the source code.
The EX4 file has already gone through the compilation process.
EX4 vs MQ4: What Is the Difference?
|
Feature |
MQ4 |
EX4 |
|
File type |
Source code |
Compiled program |
|
Normally editable |
Yes |
No |
|
Used by MetaEditor |
Yes |
No, as source |
|
Used by MT4 |
Compiled version required |
Yes |
|
Human-readable code |
Yes |
No |
|
Can be modified directly |
Yes |
No |
|
Main purpose |
Development |
Execution |
MetaQuotes documentation describes MQ4 as source code and EX4 as the compiled executable generated from that source. (MQL5)
This distinction is one of the most important concepts when discussing EX4 decompilation.
Why Do People Need EX4 Source-Code Recovery?
There are several legitimate reasons someone may need to recover source code from an EX4 file.
1. The Original MQ4 File Was Lost
A developer may have created an EA years ago and later lost the source-code backup.
The EX4 may still exist on an old computer, VPS, hard drive, or MetaTrader installation.
In this situation, source-code recovery may be considered as a last-resort option.
2. The Original Developer Is No Longer Available
Businesses sometimes depend on trading software created by an independent developer.
If that developer becomes unavailable, the business may still have the compiled EX4 but no editable source.
Recovery or reconstruction can potentially help preserve the software.
3. An Old EA Needs Maintenance
An older Expert Advisor may continue running while the original source code is unavailable.
If changes are required, having source code—or a reconstructed equivalent—can make future maintenance considerably easier.
4. Migration to a New Environment
Older MT4 applications may need to be reviewed or rebuilt when changing brokers, terminals, dependencies, libraries, or other parts of the trading environment.
MetaTrader 4’s file structure has changed over its history, including the introduction of the MQL4 data-folder structure in newer builds. (MQL5)
5. Understanding Legacy Trading Logic
A company may own an old trading system but no longer understand how it works.
Source-code recovery can sometimes help developers understand the application’s architecture and rebuild it into a maintainable project.
Is EX4 to MQ4 Conversion Possible?
This is one of the most common questions.
The answer requires an important distinction.
EX4 is not normally converted back into the original MQ4 source code like a document being converted from one format to another.
Compilation transforms source code into an executable representation.
The original source may contain:
- comments
- variable names
- function names
- development structure
- formatting
- source organization
- included files
- developer notes
Some of that information may not be recoverable in its original form.
Therefore, successful source-code recovery may produce code that is functionally useful without being an identical copy of the original development project.
How EX4 Decompilation Works at a High Level
A legitimate recovery process generally involves analyzing the compiled application and determining what information can be reconstructed.
At a high level, the process may involve:
1. File Assessment
The EX4 file is first examined to determine its type, compatibility, and general characteristics.
2. Compatibility Analysis
The MT4 generation or compiler environment associated with the file can matter.
Historical MetaTrader versions and MQL4 compiler changes can affect how older applications behave. MetaQuotes notes that older EX4 files could continue operating after the Build 600+ structural changes without automatically being recompiled. (MQL5)
3. Program Structure Analysis
The application can be analyzed to identify recoverable program structures and functionality.
4. Source Reconstruction
Where technically possible, recovered information can be organized into readable MQL4 source code.
5. Compilation
The reconstructed MQ4 code can then be reviewed and, where appropriate, compiled.
6. Testing
The resulting program should be tested against the original EX4 to determine whether its behavior is sufficiently consistent.
This final stage is extremely important.
Why Recovered MQ4 May Not Look Like the Original Source
One of the biggest misconceptions about EX4 decompilation is that the result will always be a perfect copy of the original MQ4 file.
That should not be assumed.
For example, the original source may have contained carefully organized functions and descriptive variable names. A recovered version may instead contain reconstructed structures that require cleanup and interpretation.
Similarly, comments written by the original developer may not be available.
Therefore, it is better to think about EX4 decompilation as source-code recovery or reconstruction, rather than simply pressing a button that restores the original development project.
What Affects EX4 Decompilation Results?
Several factors can influence the outcome.
EX4 Build and Compiler History
The version and compilation history of an EX4 file can matter.
Older and newer MQL4 environments have different characteristics, and MetaQuotes has documented significant changes to the MQL4 language and file structure over time. (MQL5)
File Condition
A complete, functioning EX4 is generally more useful for analysis than a damaged or incomplete file.
Program Complexity
A simple indicator and a large Expert Advisor with numerous dependencies can present very different recovery challenges.
External Dependencies
An application may depend on other components, such as:
- EX4 libraries
- DLLs
- custom indicators
- include files
- external data
- configuration files
MQL4 supports importing functions from compiled EX4 modules and external DLLs, meaning an EA may depend on components that are not contained entirely inside the primary EX4 file. (c.mql5.com)
Protection and Obfuscation
Some software may contain additional protection mechanisms.
These can make analysis substantially more difficult.
A legitimate recovery provider should identify limitations rather than promise that every protected file can be recovered perfectly.
Can Every EX4 File Be Decompiled?
No.
There is no responsible basis for guaranteeing that every EX4 can be fully restored to its original MQ4 source.
Possible outcomes include:
- successful source recovery
- partial source recovery
- functional reconstruction
- recovery requiring manual cleanup
- inability to recover sufficient information
The correct outcome depends on the individual file.
That is why a professional assessment is often more useful than a blanket promise.
EX4 Decompilation vs Rebuilding an EA
These two services are related but different.
EX4 Decompilation
The goal is to recover as much useful source-code information as possible from the compiled program.
EA Rebuilding
The goal is to recreate the application’s functionality in new MQL4 code.
Rebuilding may be appropriate when the original source cannot be fully recovered but the behavior of the existing EA can be understood through legitimate analysis and testing.
For example, a client may have:
- an EX4 file
- screenshots
- trading history
- input settings
- strategy documentation
- expected behavior
A developer can potentially use those materials to create a maintainable replacement.
What Happens After Source-Code Recovery?
Recovering MQ4 code is not necessarily the final step.
The recovered code should normally be reviewed and tested.
Important areas include:
Compilation
The MQ4 source should compile in the intended MetaEditor environment.
Trading Logic
The EA’s entry and exit behavior should be compared against the original application where practical.
Inputs
Externally configurable parameters should be checked.
Indicators
Any custom indicators used by the EA should be identified.
Libraries
Required EX4 or other dependencies should be identified and tested.
Risk Management
For trading systems, risk-related functionality deserves particular attention:
- lot sizing
- stop loss
- take profit
- maximum positions
- drawdown controls
- trading-session restrictions
Backtesting
The recovered program can be tested against historical data.
MetaQuotes provides documentation and resources for testing and optimization of Expert Advisors in the MT4 Strategy Tester. (MQL5)
Forward Testing
A recovered EA should ideally be tested in a demo or controlled environment before being used with live capital.
Can Comments and Variable Names Be Recovered?
Not necessarily.
This is another reason why recovered source code should not automatically be described as an exact copy of the original.
The original developer may have used descriptive names and comments that were useful during development. Those elements may not survive compilation in a form that can simply be restored.
A recovered project may therefore require:
- renaming variables
- reorganizing functions
- adding comments
- cleaning compiler warnings
- restructuring files
- documenting trading logic
This additional work can make the recovered project significantly more useful for long-term maintenance.
Why Source-Code Recovery Can Be Better Than Continuing With EX4 Alone
An EX4 can continue to run without MQ4 source code.
However, relying exclusively on a compiled file creates limitations.
Without source code, you may have difficulty:
- changing trading rules
- adding features
- fixing bugs
- modifying risk management
- changing indicators
- integrating new systems
- maintaining old code
- hiring another developer to make changes
Recovering or rebuilding the source can provide much greater control over the software.
EX4 Decompiler Software vs Professional Recovery
There are two broad approaches people commonly consider.
EX4 Decompiler Software
Software tools can be convenient when dealing with straightforward files and when the user understands the technical limitations.
Potential advantages include:
- fast initial analysis
- lower cost
- local processing
- convenient testing
However, results can vary considerably depending on the file.
Professional EX4 Source-Code Recovery
A professional service can be useful when:
- the file is important
- the project is complex
- dependencies are involved
- the recovered code needs cleanup
- the source needs to be tested
- the user does not have technical experience
A professional workflow can also include source-code review and functional testing rather than simply producing a file with an MQ4 extension.
How to Choose an EX4 Decompiler or Recovery Service
Before choosing a service, consider the following.
1. Does It Support MT4 EX4 Files?
Make sure the service specifically handles the type of EX4 application you have.
2. Does It Explain Limitations?
Avoid providers that promise impossible results without inspecting the file.
3. Is Testing Included?
Source recovery is much more useful when the resulting code can be compiled and tested.
4. Are Dependencies Considered?
Ask whether custom indicators, libraries, or external components need to be supplied.
5. Is Your Data Handled Securely?
An EX4 may represent valuable intellectual property.
Consider how the provider stores and handles uploaded files.
6. Does the Provider Understand MQ4?
A recovered file that technically opens but cannot be maintained is not necessarily a successful recovery.
7. Is Ownership or Authorization Clear?
Only submit files that you own or have permission to analyze.
What Should You Provide for EX4 Source-Code Recovery?
If you are requesting professional help, provide as much relevant information as possible.
Useful materials can include:
- original EX4 file
- related EX4 libraries
- custom indicators
- DLL dependencies where legally available
- set files
- screenshots
- input parameters
- EA documentation
- original MQ4 backup if one exists
- MetaTrader version/build information
- description of the required changes
The more information available, the easier it may be to understand the original application’s environment.
Common EX4 Decompilation Mistakes
Mistake 1: Treating EX4 as a Renameable File
Changing .ex4 to .mq4 does not recreate source code.
Mistake 2: Assuming Every File Is Recoverable
Technical limitations can make complete recovery impossible.
Mistake 3: Ignoring Dependencies
The primary EX4 may depend on additional libraries or components.
Mistake 4: Not Testing the Result
Recovered source code should be compiled and tested before being trusted.
Mistake 5: Expecting Perfect Original Formatting
The recovered source may require significant cleanup.
Mistake 6: Using Unauthorized Software
Source-code recovery should be limited to software you own or are authorized to analyze.
EX4 Decompilation and Intellectual Property
EX4 files can represent valuable software and trading strategies.
Before attempting source-code recovery, establish that you have the appropriate rights or authorization.
For example, legitimate cases may include:
- recovering your own EA
- recovering a company-owned trading system
- restoring software you commissioned
- maintaining legacy software where you have authorization
- analyzing software under an applicable agreement
The situation is different when attempting to obtain proprietary source code from someone else’s commercial software without permission.
When in doubt, review the applicable license or agreement and obtain authorization before proceeding.
EX4 Source-Code Recovery Checklist
Before starting a project, use this checklist:
- ☐ Confirm you own or are authorized to analyze the EX4
- ☐ Check whether the original MQ4 exists somewhere
- ☐ Back up the EX4
- ☐ Collect related libraries
- ☐ Collect custom indicators
- ☐ Record MT4/build information
- ☐ Save relevant .set files
- ☐ Document expected EA behavior
- ☐ Identify external dependencies
- ☐ Choose an appropriate recovery method
- ☐ Review the recovered MQ4
- ☐ Compile the source
- ☐ Test the recovered program
- ☐ Compare results with the original EX4
- ☐ Keep multiple backups of the recovered project
Frequently Asked Questions
What is EX4 decompilation?
EX4 decompilation is the process of analyzing a compiled MQL4 EX4 application in an attempt to recover useful source-code information or reconstruct its functionality.
Can EX4 be converted directly to MQ4?
No. EX4 is a compiled program, while MQ4 is source code. Recovering source code is a more complex process than changing a file extension.
Is an EX4 file the same as an MQ4 file?
No. MQ4 is the editable source-code format, while EX4 is the compiled format used by MetaTrader 4. (MQL5)
Can I recover the original comments?
Not necessarily. Comments and other development information may not be recoverable in their original form.
Can every EX4 be fully recovered?
No. Results depend on the individual file, its compilation history, complexity, dependencies, and other technical factors.
Can an EX4 be modified without MQ4?
The EX4 itself is not intended to be edited like MQ4 source code. If substantial changes are required, source-code recovery or rebuilding may be necessary.
What if I lost my MQ4 file?
If you still have a working EX4, source-code recovery may be worth investigating. However, first check old computers, VPS backups, cloud storage, email attachments, external drives, and previous developer archives.
Should I test recovered MQ4 code?
Yes. Compilation alone is not enough. The recovered program should be tested to determine whether it behaves as expected.
Can EX4 decompilation recover an entire EA?
Sometimes useful portions or a functional reconstruction may be possible, but complete recovery of the original development project should never be assumed.
Final Thoughts
EX4 decompilation is best understood as source-code recovery rather than a simple EX4-to-MQ4 file conversion.
The difference between MQ4 and EX4 is fundamental: MQ4 is the source-code format used during development, while EX4 is the compiled application used by MetaTrader 4. (MQL5)
If you have lost your original MQ4 source but still have the EX4, recovery may provide a path toward maintaining, rebuilding, or improving the trading application.
The most important factors are the condition and history of the EX4, its dependencies, the complexity of the application, and the quality of the recovery and testing process.
If you own the software or have authorization to analyze it, Ex4Decompiler.com can help assess an EX4 file and determine whether source-code recovery is a practical option.
Have an EX4 file and need the MQ4 source code recovered? Submit the file for an assessment and find out what recovery options may be available.