Blog Details

thumb
13 Jul 2026

What Is an EX4 File? A Complete Technical Explainer for MT4 Traders and Developers

EX4 File? A Complete Technical Explainer for MT4 Traders and Developers


Table of Contents

  • What Is an EX4 File?
  • EX4 vs MQ4: Understanding the Difference
  • What Is Inside an EX4 File?
  • MT4 Build Versions and Their Impact
  • Types of EX4 Files: EAs, Indicators, Scripts, Libraries
  • Why Would You Need to Decompile an EX4?
  • How EX4 Files Are Protected Against Decompilation
  • Limitations of EX4 Decompilation
  • Getting Professional Help

Every MetaTrader 4 user who has ever installed a trading robot, indicator, or script has encountered EX4 files. They appear in MetaTrader's file browser, they run on the chart, and they do everything a developer programmed them to do but unlike most files on your computer, you cannot open them in a text editor and read what is inside.

Understanding what an EX4 file actually is at a technical level helps explain why they behave this way, why decompilation is both useful and challenging, and what to realistically expect when you try to recover source code from one. This guide covers everything from the basics through advanced technical details about the file format itself.

What Is an EX4 File?

An EX4 file is a compiled binary executable designed to run inside the MetaTrader 4 trading platform. The "EX4" extension stands for the executable format used by MetaTrader 4 (as opposed to EX5, which is the equivalent for MetaTrader 5).

When MetaTrader loads an EX4 file, it reads the compiled binary and executes the instructions inside using MetaTrader's built-in MQL4 virtual machine runtime. This runtime handles memory management, tick processing, order execution calls, and all other interactions between the EX4 code and the broader trading infrastructure.

The EX4 format was designed with a specific goal: to allow developers to distribute their trading tools to end users without giving those users access to the underlying source code. This is standard practice in commercial software distribution you use Microsoft Word without having access to its source code but in the MetaTrader context it creates the decompilation challenge that this entire industry exists to address.

EX4 files are platform-specific: they run only inside MetaTrader 4 and cannot be executed directly by the operating system. They are not Windows executables (.exe) despite sharing some characteristics with that format. The EX4 virtual machine interprets the bytecode instructions at runtime rather than running them natively on the processor.

EX4 vs MQ4: Understanding the Difference

The distinction between EX4 and MQ4 files is similar to the distinction between an executable program (.exe on Windows) and its source code (.cpp, .py, or whatever language it was written in).

MQ4 files are the source code. They contain human-readable MQL4 programming language a proprietary language developed by MetaQuotes that resembles C/C++ in its syntax. Developers write MQ4 files in MetaEditor (the IDE built into MetaTrader) or any text editor. The source code contains comments, meaningful variable names, strategy logic expressed in readable form, and documentation the developer chose to include.

EX4 files are the compiled output. When a developer clicks "Compile" in MetaEditor, the MQL4 compiler translates the readable source code into a compact binary format optimized for execution inside MetaTrader. This process is one-way by design the compiler converts human-readable text into machine-level instructions that MetaTrader's virtual machine can execute efficiently.

Property

MQ4 Source File

EX4 Compiled File

Human readable

Yes

No (binary)

Editable

Yes

No

Contains comments

Yes

No (stripped)

Original variable names

Yes

Sometimes (depends on build)

Runnable in MT4

After compilation

Directly

Modifiable without source

Yes

No

Typical file size

5–200 KB

10–500 KB

What Is Inside an EX4 File?

Though you cannot read an EX4 file as text, it is not a completely opaque black box. EX4 files have a defined binary structure that analysis tools can parse. Understanding this structure explains both what decompilation can recover and what is irretrievably lost:

File Header

Every EX4 file begins with a fixed-length header containing: magic bytes identifying the file as an MQL4 executable, the MT4 build version that compiled the file, the file type (EA, indicator, script, library), compilation timestamp, checksum values for integrity verification, and various flags that control behavior and protection settings. This header is always readable and provides important metadata even before any decompilation work begins.

String Table

String literals used in the code messages printed to the journal log, currency pair names, error message text, parameter labels, and sometimes even original variable names are stored in a string table within the binary. This section is readable in any hex editor and often reveals useful information about the EA's functionality without requiring full decompilation. Examining the string table is often the first step in any analysis of an unknown EX4 file.

Properties Section

Contains the EA's input parameters (visible in MetaTrader's property dialog when you attach the EA to a chart), their default values, types, and display labels. This section is largely readable and always recoverable through decompilation it defines the interface the trader sees. Input parameter names in this section are preserved even when internal variable names are not, because they must be human-readable for the property dialog to function.

Bytecode Section

The main program logic, encoded as virtual machine instructions. This is the section that decompilation must translate back into readable MQL4 source. The bytecode consists of numeric operation codes (opcodes) and their operands, interpreted by MetaTrader's MQL4 virtual machine at runtime. The size and complexity of this section varies enormously with the EA's logic simple EAs may have a few kilobytes of bytecode, while complex multi-indicator systems can have hundreds of kilobytes.

Resource Sections

Present only if the EA embeds resources images, sounds, or data files packed directly into the EX4. These resources are stored in their original format within the binary and are fully recoverable through analysis, regardless of decompilation success for the code sections.

MT4 Build Versions and Their Impact

One of the most important factors affecting whether an EX4 file can be decompiled and how much of the original source can be recovered is the MetaTrader 4 build version used to compile it. This is the single most important technical factor to understand when evaluating decompilation prospects.

MetaQuotes has released numerous MT4 builds over the years. Each iteration of the compiler introduced changes to the bytecode format, optimization strategies, and critically to what debugging information is retained in the compiled output.

A rough breakdown of build version impacts:

  • Builds before ~225: Very old format from the early days of MetaTrader. Well-documented bytecode format. Free and open-source decompilers handle these files with high success rates. Variable names often preserved.
  • Builds 225–509: Intermediate format with improved compilation. Most decompilers handle these with reasonable success. Variable name retention depends on specific compilation settings.
  • Builds 509–600: Significantly changed compilation model. Harder for public tools to handle. Professional services with specialized techniques see substantially better results than automated tools.
  • Builds 600+: Current format used by modern MT4 installations (2018–present). Public free tools frequently fail or produce unusable output. Professional services with updated methodologies are required for reliable results. This is the format used by the vast majority of active trading EAs today.

To check which build compiled an EX4 file, examine the file header using a hex editor the build version is encoded in the first few bytes of the file, alongside other metadata. Alternatively, the MT4 build version that your MetaTrader installation uses is visible in the Help > About menu.

Types of EX4 Files: EAs, Indicators, Scripts, Libraries

The EX4 format is used for four distinct types of MetaTrader 4 programs, each with different behavior and decompilation considerations:

Expert Advisors (EAs)

The most common target for decompilation. EAs run continuously on a chart and handle all automated trading decisions. They implement OnInit(), OnDeinit(), and OnTick() (or OnTimer()) event handlers. EA decompilation is the primary focus of professional services because EAs represent the most significant commercial and personal value they embody the core trading strategy.

Custom Indicators

Indicators calculate and display values on the chart without directly trading. They implement OnCalculate() as their main handler. Indicator decompilation is often requested by traders who want to understand the calculation method of a proprietary indicator or adapt it to different timeframes or parameters.

Scripts

Scripts run once and then exit they perform a specific task on demand rather than running continuously. Examples include batch order management scripts, account analysis tools, and position calculators. Decompiling scripts is generally simpler than EAs because they tend to be less complex.

Libraries

Libraries contain reusable functions imported by other EX4 files. They cannot be attached to charts directly. Library decompilation is often requested when an EA depends on a library that was lost alongside the main source code.

Why Would You Need to Decompile an EX4?

Given that EX4 files run perfectly well without decompilation, why would anyone need to convert one back to MQ4 source? Several legitimate reasons arise regularly in practice:

  1. Lost source code. The developer compiled an EX4 but lost the original MQ4 due to hardware failure, accidental deletion, or migration issues.
  2. Vendor non-delivery. A commissioned EA was delivered as EX4 only, without the MQ4 source that the contract entitled the buyer to receive.
  3. Modification needs. An EA that was running well needs parameter adjustments or logic updates that cannot be made without the source code.
  4. Security auditing. A trader wants to inspect what an EA they purchased actually does before trusting it with real funds.
  5. Platform migration. Migrating a strategy from MT4 to MT5 requires the MQL4 source as a starting point for adaptation to MQL5.
  6. Understanding inherited code. A trader taking over management of an account that used automated trading wants to understand the robot's logic.

Each of these represents a legitimate use case that the professional ex4decompiler.com service at ex4 decompiler is designed to address. Understanding the file format helps set realistic expectations about what recovery looks like and what limitations apply.

How EX4 Files Are Protected Against Decompilation

Some EX4 developers go beyond the basic compilation step and add additional layers of protection specifically designed to frustrate decompilation attempts. Understanding these techniques helps explain why professional services achieve different success rates than automated tools:

Code Obfuscation

Inserting meaningless operations, false branches, and other constructs that confuse decompilation algorithms while not affecting the EA's actual behavior. The code runs correctly but the compiled binary is harder for decompilers to interpret cleanly.

String Encryption

Encrypting string literals within the compiled binary prevents the string table analysis that often provides early insights into an EA's functionality. Encrypted strings must be decrypted at runtime, making static analysis harder.

Anti-Debugging Techniques

Some EX4 files detect when they are being analyzed with debugging tools and alter their behavior accordingly a technique borrowed from malware protection. These protections require additional countermeasures (like ScyllaHide) to bypass during analysis.

Custom Virtual Machine Layers

The most sophisticated protection approach adds an additional layer of virtual machine emulation inside the already-bytecode-based EX4. The MQL4 code runs a secondary custom VM that interprets its own encrypted bytecode making reverse engineering significantly more complex.

Limitations of EX4 Decompilation

Understanding what cannot be recovered is as important as understanding what can be:

  • Comments are not recoverable. Developer comments are stripped at the lexical analysis stage of compilation and never encoded into the binary.
  • Variable names may be generic. Depending on the build version and compilation settings, variable names may have been replaced with generic identifiers during compilation.
  • Heavily obfuscated files may fail. Very heavy obfuscation can cause decompilers to produce unusable output even for professional services.
  • The recovered code requires testing. Functionally equivalent but not character-perfect test in demo conditions before live deployment.

For a deeper technical look at the compilation process itself how MetaTrader actually converts your MQL4 into an EX4 the article on covers the full pipeline in detail. And if you are new to all of this, the  is the right place to start.

Getting Professional Help

If you have an EX4 file you need to convert back to MQ4 source code, professional decompilation is the most reliable path for any file compiled in the last several years. The service at ForexMQ5 accepts EX4 submissions for all MetaTrader 4 build versions, handles Expert Advisors, indicators, scripts, and libraries, and delivers recovered MQL4 source code with a 95% success rate.

Pricing starts at $50 per file, with results typically delivered within 24–72 hours. Their team handles the complex binary analysis work, accounting for build-version differences, protection methods, and edge cases that automated tools cannot handle. For any EX4 file that represents real value, professional service is consistently the most reliable and cost-effective option.

The ex4decompiler.com conversion process works because the compiled binary retains more structural information than is immediately apparent and expert analysis can extract that information with high fidelity. Understanding the file format, as covered in this article, explains both why this is possible and why the quality of results varies so dramatically between approaches.

What Information Is Lost During Compilation?

Understanding what gets stripped away during compilation helps explain why decompilation is never a perfect mirror of the original. When MetaEditor compiles MQL4 source code into an EX4 binary, several layers of human-readable information are permanently discarded.

Variable names are replaced with generic references. A variable a developer named lotSizeMultiplier might become var_12 or simply a numeric pointer. Comments including inline documentation, strategy notes, and version history are completely removed. Function names from the developer's own codebase are often obfuscated or compressed into shortened tokens. String labels that appear in the original as descriptive identifiers may be preserved (since MetaTrader needs them at runtime) or transformed depending on how the developer built the indicator or EA.

What remains in the binary is the functional logic: the sequence of operations, the mathematical relationships between inputs and outputs, the conditional branching that governs trade entries and exits. A skilled decompilation expert can reconstruct meaningful, human-readable MQL4 from this, but it requires experience and judgment to produce clean, usable code rather than a raw mechanical translation.

EX4 Files vs. EX5 Files: Key Differences

MetaTrader 5 uses a different compiled format the EX5 file which is architecturally distinct from EX4. EX5 files use a more modern compilation model that includes richer metadata, support for object-oriented MQL5 code, and tighter integration with the MT5 trading environment.

The decompilation challenge for EX5 is substantially greater than for EX4. The object-oriented patterns in MQL5 introduce class hierarchies, inheritance chains, and encapsulation that do not exist in MQL4's procedural model. While EX4 decompilation is a solved problem for experienced professionals, EX5 decompilation remains significantly harder and less reliable.

If you are working with an EX4 file from a MetaTrader 4 platform, you are in the best position for recovery. ForexMQ5 specializes specifically in EX4 decompilation and has built their workflow around the MT4 binary format over many years.

When Does Decompilation Make Sense?

Not every situation calls for decompilation. If you have access to the original MQL4 source, there is no reason to decompile. But several common scenarios make EX4 decompilation the practical path forward: recovering an EA whose source code was stored on a hard drive that failed, adapting a purchased EA whose developer has gone silent, auditing an EA before deploying it on a live account, or migrating a working MT4 strategy to a newer platform.

In each of these cases, the question is not whether to decompile but how and whether the resulting code is clean enough to work with confidently.

We may use cookies or any other tracking technologies when you visit our website, including any other media form, mobile website, or mobile application related or connected to help customize the Site and improve your experience. learn more

Allow