How to Convert EX4 to MQ4: What Is Actually Possible?
How to Convert EX4 to MQ4: What Is Actually Possible?
If you have an EX4 file from MetaTrader 4 and need the original MQ4 source code, you may have searched for ways to “convert EX4 to MQ4.”
The important distinction is that EX4 and MQ4 are not simply two file formats that can always be converted back and forth.
MQ4 is source code. EX4 is the compiled program produced from that source code. MetaQuotes documentation describes the normal development process as writing MQL4 source code and compiling it into an EX4 executable. (MQL5)
That means recovering MQ4 from an EX4 is better understood as source-code recovery or reconstruction, not an ordinary file conversion.
This guide explains what can realistically be recovered, what may be lost, why different EX4 files produce different results, and what you should check before attempting recovery.
EX4 vs MQ4: What Is the Difference?
Before discussing conversion, it helps to understand what each file contains.
|
File |
Purpose |
Typical use |
|
.mq4 |
MQL4 source code |
Editing and compiling |
|
.mqh |
MQL4 include/header source |
Supporting source code |
|
.ex4 |
Compiled MQL4 program |
Running in MT4 |
An MQ4 file is intended to be readable and editable by a developer. It can contain functions, variables, conditions, calculations, comments and other source-level information.
When the source is compiled, the resulting EX4 is the executable program used by MetaTrader 4. (MQL5)
Therefore:
MQ4 → EX4 is normal compilation.
EX4 → MQ4 is not a normal reverse file conversion.
Can You Convert EX4 to MQ4?
The short answer is:
It depends on the particular EX4 file and what information can be recovered from it.
There is no universal process that guarantees that every EX4 can be turned back into the developer’s original MQ4 source code.
A recovery attempt may instead produce a reconstructed version of the program that needs additional analysis, cleanup, correction and testing.
This distinction is particularly important when dealing with modern MT4 programs.
Why EX4 Cannot Simply Be Renamed to MQ4
Changing the extension does not convert the file.
For example:
MyEA.ex4
cannot simply become:
MyEA.mq4
by renaming the extension.
The internal contents remain compiled program data.
MetaQuotes describes EX4 as the compiled form of an MQL4 program, while MQ4 represents the source code used during development. (MQL5)
The relationship is therefore similar to:
Source code → compiler → executable
rather than:
File format A → File format B
This is one of the most common misunderstandings surrounding EX4-to-MQ4 recovery.
What Can Potentially Be Recovered?
Depending on the file, its compilation history and the recovery method used, useful parts of the program may potentially be reconstructed.
These can include:
Program logic
The recovered result may reveal parts of the logic responsible for:
- entries
- exits
- calculations
- indicator conditions
- order management
- risk rules
- filters
- trading sessions
- alerts
- position management
However, the recovered representation may not look like the developer’s original source.
Functions
Program functions may be reconstructed, although their original names and organization may not always survive compilation and recovery.
Variables and parameters
Some variables or externally configurable parameters may be identifiable.
Indicator calculations
For custom indicators and trading robots, mathematical calculations may sometimes be reconstructed sufficiently to understand or reproduce functionality.
Trading conditions
Conditions surrounding entries and exits can be especially important when the goal is to maintain or modify an old EA.
What May Not Be Recoverable Exactly?
This is where expectations need to be realistic.
A recovered MQ4 file is not necessarily identical to the original developer’s source code.
Information that may be missing, altered or difficult to reconstruct can include:
- original variable names
- original function names
- comments
- formatting
- source-file organization
- developer annotations
- unused code
- original include files
- external libraries
- development notes
- original project structure
For example, an original developer might have written:
CalculateEntrySignal()
A recovered representation could instead contain a mechanically generated or less meaningful function identifier.
The same applies to variables.
Instead of:
maximumDailyDrawdown
a reconstruction might contain a generic identifier.
This can make manual analysis necessary.
The Difference Between Recovery and the Original Source
This is probably the most important concept in EX4-to-MQ4 work.
Suppose the original developer created:
TradingStrategy.mq4
and compiled it into:
TradingStrategy.ex4
If the MQ4 source is lost, the objective of recovery is not necessarily to reproduce every character of the original file.
Instead, the practical objective may be to reconstruct enough source-level information to:
- understand the program,
- modify it,
- compile it,
- test it,
- and maintain it.
These are different goals.
Original source recovery
The result closely resembles the original source.
Functional reconstruction
The result attempts to reproduce the behavior of the compiled program.
Partial recovery
Only certain sections or useful components can be reconstructed.
Analysis only
The EX4 may be examined to understand functionality without producing a clean MQ4 project.
These outcomes should not be treated as equivalent.
Why MT4 Build History Matters
MetaTrader 4 changed substantially with Build 600, released in 2014.
MetaQuotes documented a revised MQL4 language, a new development environment and changes to the structure and handling of MQL4 programs. (MQL5)
Importantly, MetaQuotes also stated that old EX4 files were copied during the upgrade and were not automatically recompiled. Programs created with Build 509 or earlier could continue running in newer terminals. (MQL5)
This means an EX4’s history can matter when evaluating a recovery project.
An old EX4 and a newer EX4 should not automatically be treated as technically identical.
Build 509 vs Build 600+
The Build 509 era is especially relevant when researching older MT4 software.
After Build 600, MetaTrader 4 adopted a substantially revised MQL4 environment.
MetaQuotes documented that the new version introduced changes to MQL4, MetaEditor and the underlying program environment. (MQL5)
For source recovery, this historical distinction matters because:
- the compiler generation can differ,
- the program structure can differ,
- dependencies may differ,
- compatibility can differ,
- and recovery expectations can differ.
Therefore, identifying the approximate generation of an EX4 before starting a project can be useful.
Does a Newer MT4 Terminal Automatically Convert EX4 to MQ4?
No.
Updating MetaTrader 4 does not recreate the missing MQ4 source.
MetaQuotes specifically documented that old user programs were copied during the Build 600 upgrade rather than migrated into new source code. Old EX4 files were not automatically recompiled. (MQL5)
So if you have only:
MyRobot.ex4
installing a newer MT4 terminal does not automatically produce:
MyRobot.mq4
The compiled program remains an EX4.
What About Old EX4 Files?
Older EX4 files can have a different technical history from newer files.
MetaQuotes documented that older Build 509-and-earlier MQL4 applications could run in newer MT4 terminals without being recompiled. (MQL5)
That does not mean every old EX4 can automatically be converted into its original source.
It simply means that terminal compatibility and source-code recovery are separate questions.
An EX4 can potentially continue running even when its MQ4 source is no longer available.
What About Modern EX4 Files?
Modern EX4 files require particularly careful expectations.
The Build 600 transition introduced a substantially revised MQL4 environment, including changes to compilation and program protection. (MQL5)
Consequently, an EX4 recovery project should begin with an assessment rather than a promise that a complete original MQ4 file will be produced.
A professional assessment should consider:
- approximate build generation
- program type
- file integrity
- dependencies
- external libraries
- protection or licensing mechanisms
- whether the program relies on other files
- expected functionality
- required modifications
Can an EX4 Become a Fully Editable MQ4?
Potentially, a recovery process can produce source-like output that can then be edited.
But “editable” does not necessarily mean “identical to the original.”
There are several possible outcomes.
Outcome 1: Highly usable reconstruction
The recovered code is sufficiently understandable to compile, modify and maintain.
Outcome 2: Partial reconstruction
Important sections are recovered, but some parts require manual redevelopment.
Outcome 3: Functional recreation
The original source is unavailable, but the program’s observable behavior can be studied and reproduced.
Outcome 4: Limited recovery
Only certain information can be extracted or reconstructed.
This is why reputable recovery services should avoid promising an identical MQ4 file before inspecting the EX4.
What Happens When Dependencies Are Missing?
This is another major issue.
An EA may not be a single self-contained program.
MetaQuotes documents separate MQL4 locations for:
- Experts
- Indicators
- Scripts
- Include files
- Libraries
- Files
- Presets
and notes that libraries can exist as MQ4 source or compiled EX4 files. (MQL5)
For example, an EA might depend on:
MyEA.ex4
SignalLibrary.ex4
RiskManager.ex4
CustomIndicator.ex4
Settings.set
Recovering only MyEA.ex4 may not reproduce every dependency required to rebuild the complete project.
That is why a recovery assessment should ask for all related files, when legally available.
Why External DLLs Can Be Important
Some MQL4 programs interact with external DLLs.
If an EX4 depends on an external component, recovering the EX4 alone may not reproduce everything the original program did.
For example:
EA.ex4
↓
External DLL
↓
Additional functionality
The DLL may contain functionality that is not contained in the EX4 itself.
Therefore, if an EA stops working after reconstruction, the problem may not necessarily be the recovered MQ4 logic.
It could be a missing external dependency.
What About EX4 Indicators?
The same general principles apply to custom indicators.
A custom indicator may contain:
- calculations
- buffers
- visual objects
- alerts
- signals
- parameters
- historical-data processing
A recovery project may attempt to reconstruct these components.
However, the quality of the resulting source still depends on the particular EX4 and its dependencies.
What About EX4 Expert Advisors?
Expert Advisors are often more complicated because they may contain:
- entry logic
- exit logic
- risk management
- money management
- trading-session filters
- spread filters
- news filters
- order-management functions
- external indicators
- DLL integrations
- licensing systems
Consequently, a large EA can require considerably more reconstruction and testing than a small indicator.
What About EX4 Scripts?
Scripts can also be recovered or analyzed, depending on the individual file.
Because scripts often perform a specific task rather than continuously managing a trading strategy, the recovery objective may be simpler in some cases.
But complexity still varies significantly between programs.
A Practical EX4-to-MQ4 Recovery Workflow
If you have an EX4 and need source code, a sensible workflow looks like this.
Step 1: Preserve the Original EX4
Make a backup before doing anything else.
Keep the original file untouched.
For example:
Original/
MyEA.ex4
Working/
MyEA.ex4
Do not modify your only copy.
Step 2: Identify the Program Type
Determine whether the file is:
- Expert Advisor
- custom indicator
- script
- library
This affects how the program should eventually be tested.
Step 3: Collect Related Files
Look for:
- EX4 files
- MQ4 files
- MQH files
- custom indicators
- libraries
- DLLs
- configuration files
- presets
- documentation
A complete project may contain more than one executable.
Step 4: Identify the MT4 Environment
Record:
- MT4 terminal version
- approximate EX4 generation
- original development environment if known
- whether the program was originally built for an older terminal
MetaQuotes documented significant changes beginning with Build 600, so this information can be useful when evaluating compatibility. (MQL5)
Step 5: Assess the EX4
Before promising a result, examine the available file and determine what kind of recovery may be realistic.
The assessment should establish whether the objective is:
- source reconstruction,
- functional recreation,
- modification,
- compatibility work,
- or analysis.
Step 6: Reconstruct the Required Source
If recovery is technically viable, the resulting source should be treated as reconstructed code rather than automatically assuming it is the developer’s original project.
The source may require:
- renaming,
- formatting,
- restructuring,
- dependency replacement,
- error correction,
- compatibility changes.
Step 7: Compile the MQ4
Once a usable source representation exists, compile it in the appropriate MQL4 environment.
Compilation is the normal process that turns MQL4 source into an executable EX4. (MQL5)
If the reconstructed source produces compiler errors, those errors need to be fixed before the program can be considered usable.
Step 8: Compare the Reconstructed Program
Do not assume that successful compilation means successful recovery.
The rebuilt program should be compared with the original EX4 where practical.
For an EA, useful tests can include:
- initialization
- indicator signals
- entries
- exits
- stop loss
- take profit
- position sizing
- trade filters
- alerts
- account conditions
Step 9: Backtest Before Live Trading
If the recovered program is an Expert Advisor, test it before using it on a live account.
A useful progression is:
Compile → Backtest → Demo → Forward test → Live
The exact process depends on the EA and trading requirements.
The important point is that a recovered source file should not automatically be considered production-ready simply because it compiles.
What “Successful Conversion” Should Mean
The phrase “EX4 to MQ4 conversion” can mean several different things.
File conversion
Changing one file extension into another.
Not sufficient.
Source recovery
Reconstructing source-level code from the available compiled program.
Potentially useful.
Functional reconstruction
Rebuilding code that reproduces the behavior of the original program.
Potentially useful when exact source is unavailable.
Original-source restoration
Recovering the exact source written by the original developer.
Should never be assumed to be guaranteed.
This distinction should be made clear before starting a project.
Common EX4-to-MQ4 Mistakes
Mistake 1: Assuming EX4 is just compressed MQ4
It is not simply a renamed or compressed source file.
EX4 is a compiled program.
Mistake 2: Expecting the original comments
Comments written by the developer are source-level information and should not be assumed to survive compilation and recovery.
Mistake 3: Expecting original variable names
The recovered representation may use different names.
Mistake 4: Ignoring dependencies
An EA may rely on indicators, libraries, DLLs or other files.
Mistake 5: Testing only compilation
A program can compile and still behave differently from the original.
Mistake 6: Assuming all EX4 files are equally recoverable
EX4 files can come from different compiler generations and have different structures, dependencies and protection mechanisms.
How to Choose an EX4-to-MQ4 Recovery Service
If you are looking for an online service, avoid judging the service solely by the phrase “EX4 to MQ4 decompiler.”
Ask practical questions first.
1. Do you inspect the EX4 before starting?
A serious assessment should happen before making technical promises.
2. Do you distinguish source recovery from recreation?
These are different deliverables.
3. Do you handle dependencies?
Ask specifically about:
- EX4 libraries
- custom indicators
- MQH files
- DLLs
- external files
4. Do you provide a testable MQ4?
If source code is produced, ask whether it can be compiled and tested.
5. How is confidentiality handled?
If the file contains proprietary trading logic, confidentiality matters.
6. Is the work authorized?
You should have the legal right or permission to analyze and recover the software.
Is EX4-to-MQ4 Recovery Guaranteed?
No responsible technical explanation should guarantee that every EX4 can be converted into the exact original MQ4.
The result depends on the individual file and the recovery objective.
A better way to describe the process is:
EX4-to-MQ4 recovery attempts to reconstruct usable MQL4 source from a compiled EX4 program.
That wording reflects the technical reality much better than claiming that every EX4 can simply be converted back into its original source.
Frequently Asked Questions
Can I rename EX4 to MQ4?
No. Renaming the extension does not turn compiled EX4 data into MQL4 source code.
Can EX4 be converted to MQ4?
Source recovery may be possible for some files, but it should not be treated as a guaranteed one-click conversion.
Will the recovered MQ4 be identical to the original?
Not necessarily. Original names, comments, formatting, project organization and dependencies may not be fully preserved.
Does MT4 automatically create MQ4 from EX4?
No. Updating MT4 does not recreate missing MQ4 source files. MetaQuotes documented that old EX4 files were copied during the Build 600 upgrade rather than automatically recompiled. (MQL5)
Does Build 509 matter?
Yes. Build history can matter because MT4’s MQL4 environment changed substantially beginning with Build 600. (MQL5)
Can an EX4 Expert Advisor be recovered?
It may be possible to reconstruct useful source-level logic, depending on the specific program, its dependencies and the recovery method.
Can an EX4 indicator be recovered?
Potentially, although the result depends on the individual indicator and its technical characteristics.
What if the EX4 uses a DLL?
The DLL may contain functionality outside the EX4, so the DLL and other dependencies may need to be considered separately.
Should I test recovered MQ4 code?
Yes. Compilation alone is not enough. Functional testing, backtesting and demo testing are important before relying on recovered trading software.
Can every EX4 be recovered?
No. Recovery results vary between files, and an exact recreation of the original source should not be assumed.
Final Takeaway
EX4 to MQ4 is not a simple file-format conversion.
MQ4 represents source code, while EX4 is the compiled program used by MetaTrader 4. (MQL5)
When the original MQ4 has been lost, the practical goal is usually source-code recovery or functional reconstruction.
What can actually be recovered depends on the individual EX4, its compiler generation, dependencies, protection, complexity and the intended objective.
For an old EA, indicator or script, the most useful approach is therefore:
Preserve the EX4 → identify its environment → collect dependencies → assess recovery → reconstruct source → compile → compare behavior → test thoroughly.
And most importantly, only perform source recovery on software you own or are authorized to analyze.