EX4 vs MQ4: Key Differences Between EX4 and MQ4 Files in MetaTrader 4
If you use MetaTrader 4 for forex trading, you have probably encountered files with EX4 and MQ4 extensions.
Although both file types are associated with MetaTrader 4 and MQL4 development, they serve very different purposes.
Understanding the difference between EX4 and MQ4 is especially important if you use Expert Advisors, custom indicators, automated trading systems, or older MetaTrader 4 projects.
In simple terms:
MQ4 is source code. EX4 is compiled code.
But there is more to the difference than the file extension.
This guide explains what MQ4 and EX4 files are, how they work, when you need each one, and what options may be available if you have an EX4 but have lost the original MQ4 source code.
What Is an MQ4 File?
An MQ4 file contains source code written using the MQL4 programming language.
MQL4 is used to create programs for MetaTrader 4, including:
- Expert Advisors
- Custom indicators
- Scripts
- Trading utilities
- Automated trading tools
Because MQ4 is source code, it can normally be opened and edited by a developer using the appropriate MetaTrader development environment.
For example, a developer can modify an MQ4 file to change:
- Entry conditions
- Exit conditions
- Stop-loss rules
- Take-profit settings
- Position sizing
- Trading hours
- Indicator calculations
- Risk-management rules
- Alerts
- Other program functionality
After making changes, the MQ4 source can be compiled into an EX4 file.
What Is an EX4 File?
An EX4 file is a compiled MetaTrader 4 program.
When MQL4 source code is compiled, MetaTrader produces an executable form that the platform can use.
The simplified process is:
MQ4 → Compile → EX4
An EX4 file may represent an:
- Expert Advisor
- Custom indicator
- Script
The EX4 is designed to be used by MetaTrader 4 rather than edited like ordinary source code.
EX4 vs MQ4 at a Glance
|
Feature |
MQ4 |
EX4 |
|
File type |
Source code |
Compiled program |
|
Platform |
MetaTrader 4 |
MetaTrader 4 |
|
Language |
MQL4 |
Compiled MQL4 |
|
Normally editable |
Yes |
No, not like source code |
|
Used for development |
Yes |
No |
|
Used by MT4 for execution |
Source is compiled first |
Yes |
|
Can be modified directly |
Yes |
Limited |
|
Suitable for source-code recovery |
Source already available |
May require recovery |
The most important difference is simple:
MQ4 is intended for development and editing, while EX4 is intended for execution by MetaTrader 4.
How MQ4 Becomes EX4
A developer normally writes an Expert Advisor or other MQL4 program in source-code form.
For example, the project may contain:
MyTradingEA.mq4
The developer then compiles the source.
The result may be:
MyTradingEA.ex4
The EX4 is the compiled version that MetaTrader 4 can load.
If the developer later wants to make significant changes, having the original MQ4 source is extremely useful.
Why Is the MQ4 Source Code Important?
Source code provides access to the logic behind an automated trading system.
For an Expert Advisor, that can include:
Entry Logic
Rules determining when a trade should be opened.
Exit Logic
Conditions determining when positions should be closed.
Risk Management
Rules controlling position size, stop loss, drawdown, and exposure.
Indicators
Calculations involving moving averages, RSI, MACD, Bollinger Bands, or custom indicators.
Trade Management
Rules for trailing stops, break-even, partial exits, and other position-management functions.
User Inputs
Parameters that allow traders to configure the EA.
Without the MQ4 source, making modifications to these components can be considerably more difficult.
Why Do Traders Often Have EX4 but Not MQ4?
This situation is relatively common.
A trader may receive an EX4 file when purchasing an Expert Advisor but never receive the original source code.
Other situations include:
- The developer kept the source private.
- The MQ4 file was accidentally deleted.
- An old computer was lost.
- A hard drive failed.
- A VPS was replaced.
- Backups were incomplete.
- The original developer is no longer available.
- An old trading project was recovered from an archive containing only compiled files.
In these cases, the EX4 may be the only remaining copy of the program.
Can You Edit an EX4 File Like an MQ4?
No—not in the same way.
An MQ4 file is source code designed to be edited.
An EX4 is compiled code.
If you want to change the underlying strategy logic, having the original MQ4 source is normally the preferred option.
If the MQ4 source has been permanently lost, technical source-code recovery may be considered, depending on the specific EX4 and your rights to analyze it.
What Is EX4 Source-Code Recovery?
EX4 source-code recovery is the process of analyzing a compiled EX4 program and attempting to reconstruct usable MQL4 source-code information.
The purpose may be to:
- Recover a lost project
- Maintain an old EA
- Fix software issues
- Modify trading logic
- Update functionality
- Preserve legacy trading software
However, recovery should not be confused with a guaranteed conversion back to the exact original MQ4 file.
The result can depend on the EX4’s characteristics.
Can Every EX4 Be Converted Back to MQ4?
No.
This is an important limitation.
The possibility and quality of source-code recovery can depend on factors such as:
- EX4 version
- Compilation characteristics
- Protection
- Obfuscation
- Encryption
- External dependencies
- Program complexity
- File integrity
A recovered project may also differ from the original source in areas such as comments, variable names, formatting, and project structure.
Therefore, it is better to think of EX4 decompilation as source-code recovery or reconstruction, rather than assuming it is a perfect reverse conversion.
EX4 and MQ4 for Expert Advisors
Expert Advisors are one of the most common reasons traders encounter these files.
A typical development workflow looks like this:
1. Developer writes MQ4 source
↓
2. Source code is compiled
↓
3. EX4 is created
↓
4. EX4 is installed in MetaTrader 4
↓
5. MT4 loads the EA
The MQ4 file is primarily part of the development process.
The EX4 is primarily used by MetaTrader 4.
EX4 vs MQ4 for Custom Indicators
The same basic concept applies to custom indicators.
A developer can create an indicator using MQL4 source code.
For example:
MyIndicator.mq4
After compilation:
MyIndicator.ex4
The EX4 can then be used in MetaTrader 4.
If the source code is lost, maintaining or changing the indicator may become more difficult.
EX4 vs MQ4 for Scripts
Scripts can also be developed in MQ4 and compiled into EX4.
A script might perform tasks such as:
- Trade management
- Order operations
- Chart utilities
- Data processing
- Alerts
- Automation functions
Again, the source file provides the editable development logic, while the compiled EX4 is intended for execution.
Does an EX4 Contain the Original MQ4?
An EX4 should not be treated as a simple container holding the original MQ4 file.
Compilation transforms the source code into a compiled representation.
As a result, information from the original development project may not remain available in its original form.
For example, the compiled file may not preserve the original:
- Comments
- Formatting
- Variable names
- Project structure
- Documentation
This is one reason source-code recovery can be technically challenging.
What Happens If You Lose Your MQ4?
If you have lost your MQ4 but still have the EX4, do not immediately delete or replace the EX4.
Instead:
Step 1: Preserve the EX4
Create an untouched backup.
Step 2: Search for the Original MQ4
Check:
- Old computers
- VPS backups
- Cloud storage
- USB drives
- Email attachments
- Development folders
- Previous versions
Step 3: Collect Related Files
Look for:
- EX4 files
- MQ4 files
- Custom indicators
- DLLs
- Libraries
- Presets
- Documentation
Step 4: Test the Original EA
Document how the existing EX4 behaves.
Step 5: Consider Source-Code Recovery
If the original MQ4 cannot be found, determine whether technical recovery is possible.
Why You Should Keep Both MQ4 and EX4
If you develop your own MetaTrader 4 software, keeping both files is good practice.
Maintain secure backups of:
- MQ4 source
- EX4 compiled files
- Custom indicators
- Libraries
- DLLs
- Presets
- Documentation
- Version history
The MQ4 gives you the ability to maintain and update the project.
The EX4 provides a compiled version that can be deployed to MetaTrader 4.
Having both reduces the risk of losing an important trading project.
Is MQ4 Better Than EX4?
Neither is simply “better.”
They serve different purposes.
MQ4 is better for development.
EX4 is better for distributing and running the compiled program.
For a software developer, the MQ4 source is usually the more valuable file because it provides access to the underlying code.
For a trader who simply wants to run an EA, the EX4 may be all that is required.
Security and Intellectual Property
Source code can contain valuable intellectual property.
An EA’s MQ4 file may reveal:
- Trading strategy logic
- Risk-management methods
- Proprietary calculations
- Internal algorithms
- Business logic
For this reason, developers often distribute only the compiled EX4 rather than the MQ4 source.
If you have an EX4 that belongs to someone else, make sure you have the appropriate permission before attempting to analyze, modify, or recover its source code.
Frequently Asked Questions
What is the main difference between EX4 and MQ4?
MQ4 is editable MQL4 source code, while EX4 is the compiled version used by MetaTrader 4.
Can I edit an MQ4 file?
Yes. MQ4 is source code and is intended to be edited and compiled by developers.
Can I edit an EX4 file?
An EX4 is compiled, so it cannot normally be edited in the same way as an MQ4 source file.
Can EX4 be converted to MQ4?
Source-code recovery may be possible in some cases, but an exact recreation of the original MQ4 is not guaranteed.
Is EX4 the executable version of MQ4?
In simple terms, yes. MQ4 source code can be compiled into an EX4 program that MetaTrader 4 can execute.
What should I do if I lost my MQ4?
First search your backups and old development environments. If the MQ4 cannot be found but you have the EX4, you can investigate whether source-code recovery is technically possible.
Is EX4 decompilation always successful?
No. Results depend on the specific EX4 and factors such as its version, protection, complexity, and dependencies.
Should I back up my MQ4?
Absolutely. If you develop an EA or other MQL4 software, maintaining secure backups of your source code is strongly recommended.
Final Thoughts
The difference between EX4 and MQ4 is fundamental to understanding MetaTrader 4 software.
MQ4 is the source code used to develop and modify MQL4 programs. EX4 is the compiled program that MetaTrader 4 can execute.
If you have the MQ4, maintaining an EA is generally much easier because the underlying source code is available.
If you have only an EX4 because the original MQ4 has been lost, source-code recovery may be an option depending on the specific file and your authorization to analyze it.
For any important Expert Advisor, the best long-term approach is to preserve the original MQ4 source, compiled EX4, dependencies, documentation, and backups.
Lost your MQ4 source code? If you still have the original EX4, an EX4 source-code recovery assessment can help determine what may be recoverable from your MetaTrader 4 program.