EX4 File Documentation


Summary

An MetaTrader Program File (.ex4) is a compiled program for the MetaTrader 4 (MT4) trading platform: an Expert Advisor (trading robot), a custom indicator, or a script. Its MIME type is application/octet-stream. You do not open it like a document; you install it by copying it into MT4’s MQL4 folder and attaching it to a chart. It runs only inside MT4. Because .ex4 is the compiled output of an .mq4 source file, you cannot edit it, and modern .ex4 files cannot be reliably decompiled.

Technical details

FeatureValue
Full nameMetaTrader 4 Compiled Program (Expert Advisor / Indicator / Script)
File extension.ex4
MIME typeapplication/octet-stream
Format typeCompiled MQL4 program for the MetaTrader 4 terminal (binary)
DeveloperMetaQuotes Software Corp.
Introduced2005 (MetaTrader 4 platform)
Source languageMQL4 (compiled from an .mq4 source file in MetaEditor)
RuntimeMetaTrader 4 terminal only — not a native OS executable
Program kindsExpert Advisor (robot), custom indicator, script
Magic numberNone documented — proprietary, undocumented internal format
Format changeOverhauled and hardened in MT4 build 600 (February 2014)
Open standardNo — closed, proprietary format
EditableNo — compiled output; edit the .mq4 source instead
Decompile to sourceNot reliably possible for build-600+ files (and usually a licence violation)
Install locationMQL4\Experts, MQL4\Indicators, or MQL4\Scripts
MT5 equivalent.ex5 (compiled from .mq5)
Related extensions.mq4, .ex5, .mq5, .set, .tpl
Documentationmql5.com/en/docs

What is an EX4 file?

EX4 is the compiled, runnable form of an MQL4 program for MetaTrader 4 (MT4), the Forex and CFD trading platform released by MetaQuotes Software Corp. in 2005. A developer writes source code in the MQL4 language (an .mq4 file) using the MetaEditor tool, compiles it, and the output is an .ex4 that the MT4 terminal loads and runs. It is a compiled program, not a document, and it runs only inside MetaTrader 4, not as a normal Windows executable.

Three kinds of program ship as .ex4: Expert Advisors (EAs, the automated trading robots that place and manage trades), custom indicators (studies drawn on charts), and scripts (one-shot actions run once on demand). The format is deliberately closed. Unlike the ZIP-based or text formats documented elsewhere on this site, .ex4 has no published structure and no stable magic number, because MetaQuotes ships the compiled binary precisely to keep the author’s source hidden. This article is honest about what can and cannot be known about it.

EX4 versus MQ4: source and compiled output

The pairing to understand is .mq4 and .ex4. An .mq4 file is human-readable MQL4 source: a text file you can open and edit in MetaEditor. Compiling it produces an .ex4, the machine-oriented program the terminal actually executes. The relationship runs one way. Compilation discards the source, comments and original names, so you cannot open an .ex4 and read the strategy, and there is no “edit the .ex4” workflow: to change how a robot behaves you edit its .mq4 and recompile. If a seller gave you only the .ex4, they intentionally withheld the source, which is common for commercial EAs.

Internally an .ex4 holds the compiled MQL4 program that the terminal’s runtime executes, an internal marker of which kind of program it is (Expert Advisor, indicator or script), and the set of input parameters the program exposes when you attach it to a chart. Beyond that, the byte-level layout is proprietary and has never been documented by MetaQuotes, so this page does not invent offsets or field names for it.

The build 600 change: why old decompilers stopped working

The single most important fact about the format is that it changed. With MT4 build 600, released in February 2014, MetaQuotes overhauled the MQL4 language and the compiled .ex4 format together, adding stronger protection and a different internal structure. Files compiled before build 600 had a simpler layout that some “decompiler” tools of the era could partly reverse into approximate source. Files compiled from build 600 onward are obfuscated and, in practice, cannot be decompiled by any reliable automated tool. This is why advice from before 2014 about recovering MQL4 source no longer applies to modern files.

Why "ex4 to mq4 decompiler" is a dead end

A large share of searches for this extension want to turn an .ex4 back into editable .mq4 source. For modern files this is not possible, and pursuing it is risky. The sites advertising an “ex4 to mq4 decompiler” fall into three groups, none good: tools that simply do not work on build-600+ files, scams that take payment and deliver nothing, and outright malware that uses the promise of a decompiler to get you to run a hostile program. There is also a legal problem: decompiling someone else’s Expert Advisor typically breaks the licence you agreed to when you bought it. If you genuinely need the source, the only legitimate route is to obtain the .mq4 from the author or vendor. Treat every “free EA” and “decompiler” download as suspect until proven otherwise.

Installing an EX4 into MetaTrader 4

You install an .ex4 by placing it in the correct folder of MT4’s data directory, then loading it from the terminal. The folders are specific to the program type:

<MT4 data folder>\MQL4\Experts       Expert Advisors (trading robots)
<MT4 data folder>\MQL4\Indicators   custom indicators
<MT4 data folder>\MQL4\Scripts      scripts (one-shot actions)

In MT4, choose File → Open Data Folder to reach this directory, copy the .ex4 into the matching subfolder, then restart the terminal or refresh the Navigator panel. The program then appears in the Navigator, and you attach it by dragging it onto a chart. Expert Advisors additionally require “Allow automated/algo trading” to be enabled before they will trade. MetaTrader 4 is Windows software; on macOS or Linux you run it through your broker’s Wine-based bundle or on a Windows VPS, and install the .ex4 the same way.

EX4 versus EX5, and why neither converts to an EXE

The MetaTrader 5 counterpart is .ex5, compiled from .mq5 source and run by the MT5 terminal. An .ex4 and an .ex5 are not interchangeable and there is no converter between them; moving a strategy from MT4 to MT5 means rewriting or recompiling the source for MQL5, not converting the compiled file. Likewise an .ex4 cannot be turned into a standalone Windows .exe. Despite the “ex” in its name, it is not a native executable: it only means anything to the MetaTrader 4 runtime that interprets it, so there is nothing to convert it into that would run on its own.

Frequently asked questions

Can I decompile an .ex4 back to .mq4 source?

Not reliably. Compilation removes the source, and since MT4 build 600 (February 2014) the .ex4 format is obfuscated against decompilation, so no automated tool recovers usable source from a modern file. The “ex4 to mq4 decompiler” sites are unreliable, scams, or malware, and decompiling another author’s EA usually violates its licence. To get the source, ask the author for the .mq4.

I copied the .ex4 into MT4 but nothing happens. Why?

Check that it went into the right subfolder for its type (MQL4\Experts for a robot, MQL4\Indicators for an indicator, MQL4\Scripts for a script) and that you refreshed the Navigator or restarted MT4. An Expert Advisor also needs “Allow algo/automated trading” enabled before it will run, and it does nothing until you drag it onto a chart.

References