Blog Details

thumb
01 Oct 2026

EX4 Decompiler: Recovering and Rebuilding MetaTrader 4 Source Code

EX4 Decompiler: Recovering and Rebuilding MetaTrader 4 Source Code

When an old MetaTrader 4 Expert Advisor, indicator, or trading utility still exists as an EX4 file but the original MQ4 source code has been lost, the biggest question is not simply whether the file can be opened.

The real question is:

Can the functionality be recovered, reconstructed, or rebuilt into maintainable MQL4 source code?

This is where the terms EX4 decompiler, EX4 source-code recovery, MQ4 reconstruction, and MT4 redevelopment become relevant.

An MQ4 file is source code, while EX4 is the compiled program produced from MQL4 source. MetaQuotes’ documentation and MQL4 community documentation distinguish these file types clearly: MQ4 is used for development, while EX4 is the compiled form used by the terminal. (MQL5)

However, recovering an EX4 is not necessarily the same as obtaining the original MQ4 project. In many situations, the practical objective is to rebuild the required functionality into a new, maintainable MQL4 project.

Important: EX4 analysis and source recovery should only be performed on software you own or are authorized to analyze. This article focuses on legitimate recovery, maintenance, reconstruction, and redevelopment rather than bypassing licensing or software protection.

What Is an EX4 File?

An EX4 file is a compiled MetaTrader 4 application.

MQL4 can be used to create:

  • Expert Advisors
  • Custom indicators
  • Scripts
  • Libraries

The simplified development process is:

MQ4 source code → compilation → EX4 executable

The MQ4 source contains the instructions written by the developer.

The EX4 is the compiled program that MetaTrader 4 executes.

MetaQuotes documentation describes MQL4 source files and compiled EX4 programs as different parts of the development process. (MQL5)

What Is an MQ4 File?

An MQ4 file contains MQL4 source code.

For example:

TradingEA.mq4

A developer can open the source in MetaEditor, make changes, and compile it to produce:

TradingEA.ex4

Complex projects may also contain MQH include files and separate libraries.

This means that the original development project can contain considerably more information than the final EX4 file.

EX4 vs MQ4

Feature

MQ4

EX4

File type

Source code

Compiled program

Intended use

Development

Execution

Normal editing

Yes

No

Opened as source in MetaEditor

Yes

No

Compilation required

Produces EX4

Already compiled

Original comments

Available if present

Not guaranteed

Original project structure

Potentially available

Not necessarily preserved

Modification

Edit and recompile

Requires source or reconstruction

This distinction explains why an EX4 cannot simply be treated as an editable MQ4 file.

What Is an EX4 Decompiler?

An EX4 decompiler generally refers to a tool or process intended to analyze an EX4 program and attempt to recover information about the underlying application.

The theoretical direction is:

EX4 → reconstructed source

But the process is not necessarily a perfect reversal of compilation.

A compiled program can contain considerably less developer-facing information than the original project.

For example, the original project may have contained:

  • Comments
  • Meaningful variable names
  • MQH files
  • Multiple source files
  • Documentation
  • Original formatting
  • External libraries
  • DLL dependencies

Those elements may not all be recoverable from one EX4.

Recovery Is Different From Rebuilding

This distinction is particularly important.

Source-Code Recovery

The objective is to recover or reconstruct source code from the available program.

Source-Code Reconstruction

The objective is to create maintainable MQL4 source based on the information that can be established about the existing program.

Rebuilding

The objective is to create a new MT4 application that reproduces the required functionality.

These three approaches can overlap.

A project might begin as an EX4 recovery assessment and eventually become a complete redevelopment project.

Why Rebuilding Can Be Necessary

Imagine an old Expert Advisor that:

  • Still runs
  • Has no MQ4 source
  • Uses outdated dependencies
  • Needs new features
  • Has no available developer
  • Must be maintained

Even if the original source cannot be restored exactly, the functionality may still be understood sufficiently to build a new MQL4 implementation.

The new project might reproduce:

  • Entry logic
  • Exit logic
  • Risk management
  • Position sizing
  • Indicators
  • Trading filters
  • Session rules
  • Order management

The resulting MQ4 would be new source code, not necessarily the original source.

That distinction should be documented clearly.

How MetaTrader 4 Source Code Is Built

The standard workflow is straightforward.

Step 1 — Write MQ4

The developer creates MQL4 source code.

Step 2 — Compile

MetaEditor compiles the source.

Step 3 — Produce EX4

The resulting EX4 is the executable program used by MT4.

MetaQuotes describes compilation as the process that turns MQL source into the executable representation used by the terminal. (MQL5)

This is why recovering source from EX4 is fundamentally different from ordinary MQL4 development.

Why You Cannot Simply Rename EX4 to MQ4

Changing the filename:

EA.ex4

to:

EA.mq4

does not recreate source code.

The file’s internal representation does not change simply because its extension changes.

If you have the original MQ4, the normal process is:

Edit MQ4 → Compile → New EX4

If you only have EX4, a separate recovery, reconstruction, or redevelopment process is required.

MQL4 community guidance also explicitly distinguishes EX4 files from editable MQ4 source files. (MQL5)

The Role of MT4 Build History

The history of MetaTrader 4 is especially important when discussing EX4 recovery.

MetaQuotes released Build 600 on February 3, 2014, describing it as a major update that included a revised MQL4 language, new MetaEditor, changes to the terminal structure, and substantially revised protection for compiled applications. (MQL5)

This creates an important distinction between older and newer EX4 files.

Older Build 509 Programs

Older MQL4 applications were produced using the earlier MQL4 development environment.

MetaQuotes documented that existing programs compiled by the older compiler could continue operating after the Build 600 transition. Old EX4 files were not automatically recompiled during the upgrade. (MQL5)

Build 600 and Later

Build 600 introduced major changes to MQL4 and its compiler.

MetaQuotes also stated that protection of MQL4 applications was raised substantially, with new EX4/EX5 programs receiving revised protection. (MQL5)

For this reason, the age and compiler generation of an EX4 should be considered before making claims about source recovery.

Can Modern EX4 Files Be Decompiled?

This question requires careful wording.

There are longstanding community discussions about modern EX4 decompilation. MQL4 forum moderators have stated that there has been no publicly demonstrated general-purpose decompilation of EX4/EX5 programs since the Build 600 transition, while other community participants have made different claims. (MQL5)

These forum discussions should not be interpreted as proof about every individual EX4.

The practical lesson is:

Do not promise exact source recovery before the actual file has been assessed.

The recovery possibilities can depend on:

  • File generation
  • Protection
  • Dependencies
  • Program complexity
  • Available supporting files
  • Required functionality

Recovering vs Rebuilding an Expert Advisor

Suppose you have:

MyEA.ex4

but no:

MyEA.mq4

There are several possible outcomes.

Outcome 1 — Source Is Available Elsewhere

A backup, old computer, VPS, developer archive, or previous installation may contain the MQ4.

This is the ideal situation.

Outcome 2 — Partial Source Is Available

You may find:

MyEA.mq4

RiskManager.mqh

but other files are missing.

The project may be reconstructed using the remaining source and dependencies.

Outcome 3 — Only EX4 Is Available

The project becomes an EX4 assessment and source-reconstruction problem.

Outcome 4 — Original Logic Cannot Be Reliably Recovered

A new MT4 implementation may need to be developed based on documented behavior and requirements.

What Can Be Rebuilt?

A new MQL4 implementation can potentially reproduce many functional areas.

Trading Logic

Examples include:

  • Buy conditions
  • Sell conditions
  • Entry filters
  • Exit conditions
  • Stop-loss rules
  • Take-profit rules

Risk Management

Examples include:

  • Fixed lot sizing
  • Percentage risk
  • Maximum trades
  • Daily limits
  • Drawdown controls
  • Position limits

Indicator Logic

Examples include:

  • Moving averages
  • RSI
  • MACD
  • Bollinger Bands
  • Custom calculations
  • Multi-timeframe signals

Trade Management

Examples include:

  • Trailing stops
  • Break-even rules
  • Partial closes
  • Pending orders
  • Order modifications

The exact implementation depends on what can be established from the available evidence.

Copy-Trading EAs

Copy-trading applications can require additional reconstruction work.

A copy-trading EA may contain:

  • Master-account monitoring
  • Receiver-account logic
  • Trade synchronization
  • Symbol mapping
  • Lot multipliers
  • Risk multipliers
  • Magic-number filtering
  • Order modification
  • External communication

It may also depend on:

  • DLLs
  • EX4 libraries
  • Configuration files
  • External servers

Consequently, rebuilding a copy-trading EA requires understanding the entire system rather than looking only at one EX4 file.

DLL Dependencies

DLLs are particularly important.

An EX4 can interact with external libraries, meaning some functionality may exist outside the MQL4 program.

Therefore:

EX4 recovery does not automatically mean DLL recovery.

If the application relies on an external DLL, the rebuilt MQ4 may need to retain the dependency or implement an authorized replacement for the required functionality.

EX4 Libraries

MetaQuotes documents that MQL4 libraries can exist as source or compiled EX4 libraries and can provide functions to other MQL4 programs. (MQL5)

For example:

MainEA.ex4

TradeLibrary.ex4

RiskLibrary.ex4

If one of these libraries is missing, the main EA may not be completely understandable or reproducible.

This is why a recovery assessment should request the entire available project rather than only one EX4.

MQH Include Files

The original project may also contain files such as:

TradeFunctions.mqh

RiskManager.mqh

Indicators.mqh

These can contain source code used by the main MQ4 file.

If these files still exist, they can significantly reduce the amount of reconstruction required.

A Practical EX4 Recovery and Rebuild Workflow

A professional project can follow a structured process.

1. Collect the Available Files

Start with:

  • EX4
  • MQ4
  • MQH
  • DLL
  • EX4 libraries
  • Presets
  • Configuration files
  • Documentation
  • Screenshots
  • Previous versions

2. Determine the Program Type

Identify whether the file is:

  • Expert Advisor
  • Indicator
  • Script
  • Library

3. Establish the MT4 Environment

Record:

  • MT4 build
  • Approximate file age
  • Broker environment if relevant
  • Whether the program still runs
  • Known dependencies

4. Map the Architecture

Determine how the program interacts with:

  • Indicators
  • Libraries
  • DLLs
  • Files
  • External services
  • Trading functions

5. Define the Required Outcome

This is critical.

Do you need:

  • The original source?
  • Editable source?
  • A particular bug fixed?
  • A new feature?
  • A fully rebuilt EA?
  • Documentation?
  • Migration to another environment?

The answer changes the technical strategy.

6. Attempt Appropriate Recovery

Where technically and legally appropriate, available program information can be analyzed to determine what can be reconstructed.

7. Rebuild Missing Components

If exact recovery is not realistic, missing functionality can be implemented as new MQL4 source.

8. Compile the New MQ4

The rebuilt project can then be compiled using MetaEditor.

9. Test Against the Original

If the original EX4 still works, compare its behavior with the new version.

Testing a Rebuilt MT4 Program

Testing is one of the most important stages.

A new MQ4 file that compiles successfully is not automatically equivalent to the old EX4.

Compilation Testing

Check that the source compiles without critical errors.

Strategy Testing

Use historical data to compare behavior.

Demo Testing

Run the rebuilt program in a demo environment before considering live use.

Functional Testing

Compare:

  • Entries
  • Exits
  • Stop losses
  • Take profits
  • Lot calculations
  • Risk settings
  • Indicator signals
  • Alerts
  • Trade management

Edge-Case Testing

Also test conditions such as:

  • High spreads
  • Missing ticks
  • Market reopening
  • Multiple simultaneous trades
  • Partial fills
  • Symbol differences
  • Different account sizes

This is especially important for automated trading software.

How to Verify a Rebuilt EA

A useful comparison can look like this:

Test

Original EX4

Rebuilt MQ4

Inputs

Record

Compare

Entry signals

Record

Compare

Exit signals

Record

Compare

Lot size

Record

Compare

Stop loss

Record

Compare

Take profit

Record

Compare

Risk controls

Record

Compare

Indicator values

Record

Compare

Trade management

Record

Compare

Alerts

Record

Compare

The objective is not merely to prove that both programs compile.

The objective is to determine whether they behave consistently under comparable conditions.

Why Compilation Alone Is Not Enough

A common mistake is:

“The MQ4 compiled successfully, so the recovery worked.”

Compilation only establishes that the source can produce an executable.

It does not establish that the new program reproduces the original behavior.

MetaQuotes’ development documentation distinguishes source editing and compilation from program execution and testing. (MQL5)

For trading systems, even a small difference in logic can change results significantly.

Rebuilding an Indicator

Indicators require their own validation.

A rebuilt indicator should be compared for:

  • Buffer values
  • Signal timing
  • Chart objects
  • Arrows
  • Alerts
  • Timeframe behavior
  • Historical calculations

A visual similarity on one chart is not enough to prove equivalence.

Rebuilding an MT4 Script

Scripts can also be reconstructed when the required behavior is known.

For example, a script might:

  • Manage orders
  • Modify stops
  • Close positions
  • Export information
  • Create chart objects

The rebuild should be tested against the specific operation it is expected to perform.

When Source Recovery Is Better Than Rebuilding

Source recovery may be preferable when:

  • Important original logic can be reconstructed
  • Supporting source files are available
  • The application is complex
  • Existing behavior needs to be preserved
  • The project contains specialized calculations

When Rebuilding May Be More Practical

Rebuilding can make more sense when:

  • Only the EX4 remains
  • The required behavior is well documented
  • The original source structure is unavailable
  • The program needs major modernization
  • Dependencies are obsolete
  • New functionality is required anyway

The decision should be based on the actual project rather than a blanket promise that every EX4 can be restored.

Common Mistakes

Mistake 1: Treating EX4 as Source

EX4 is compiled, while MQ4 is source.

Mistake 2: Renaming the File

Changing .ex4 to .mq4 does not reconstruct the source.

Mistake 3: Ignoring Supporting Files

DLLs, libraries and MQH files can be important parts of the original system.

Mistake 4: Promising an Exact Copy

A rebuilt MQ4 can reproduce functionality without being identical to the original source.

Mistake 5: Ignoring MT4 Build History

Build 509 and Build 600+ belong to significantly different stages of MQL4’s development history.

Mistake 6: Skipping Behavioral Testing

Compilation is not functional verification.

How to Choose an EX4 Recovery Service

If you are considering professional assistance, ask the provider:

  1. Do you inspect the EX4 before starting?
  2. Do you distinguish recovery from redevelopment?
  3. Can you identify dependencies?
  4. Can you work with older and newer MT4 builds?
  5. What source format will be delivered?
  6. Is compilation included?
  7. Is functional testing included?
  8. How are DLLs handled?
  9. What happens if complete recovery is not technically possible?
  10. Do you require authorization to analyze the software?

Be cautious with claims such as:

  • “100% exact MQ4”
  • “Every EX4 can be recovered”
  • “Guaranteed original source”
  • “Works on every protected EX4”

A serious assessment should explain limitations before promising an outcome.

Frequently Asked Questions

What is EX4 source-code recovery?

It is the process of attempting to recover, reconstruct, or recreate the MQL4 functionality represented by a compiled EX4 program.

What is the difference between recovery and rebuilding?

Recovery attempts to obtain or reconstruct information from the existing program. Rebuilding creates new MQL4 source that reproduces the required functionality.

Can an EX4 always be converted into MQ4?

No. The result depends on the individual program, its generation, protection, dependencies and available supporting material.

Can I edit an EX4 directly?

Normal MQL4 editing is performed on MQ4 source. EX4 is the compiled program.

Does Build 600 matter?

Yes. Build 600 introduced major changes to MQL4, MetaEditor, the file structure and application protection. (MQL5)

Can DLL functionality be rebuilt?

Potentially, but an external DLL is a separate component. Reconstructing the MQL4 program does not automatically recreate the DLL’s original source.

Can a copy-trading EA be rebuilt?

Potentially, if the required functionality and dependencies can be established. Copy-trading systems can have multiple interacting components, so the complete architecture should be considered.

Will rebuilt MQ4 be identical to the original?

Not necessarily. New source may use different names, organization and implementation while reproducing the required behavior.

Should a rebuilt EA be tested?

Yes. It should be compiled, backtested and tested in a controlled environment before being considered for live trading.

Final Takeaway

An EX4 decompiler is only one part of the broader problem of recovering a lost MetaTrader 4 project.

The important distinction is between:

EX4 analysis

source-code recovery

source reconstruction

and

full MT4 redevelopment.

If the original MQ4 source still exists, it should normally be used rather than attempting recovery from EX4.

If only an EX4 remains, the first step should be an assessment of the program, its MT4 build history, dependencies and required functionality.

Build 600 was a major turning point in MQL4, bringing a revised language and compiler environment and substantially revised protection for compiled applications. (MQL5)

For that reason, no single recovery method should be presented as guaranteed for every EX4.

The practical objective is to determine what can be recovered, what must be reconstructed, and what may need to be rebuilt as new MQL4 source.

Once the new source exists, the work is not finished. It should be compiled, tested and compared against the original program’s behavior before it is relied upon for automated trading.