How to Edit an EX4 File: What You Can and Cannot Change

How to Edit an EX4 File: What You Can and Cannot Change

If you have an EX4 file from MetaTrader 4 and want to change its trading logic, parameters, indicators, or other functionality, there is an important distinction to understand:

An EX4 file is a compiled program, not the normal source-code file used for editing.

MetaQuotes documentation and MQL4 community guidance distinguish between MQ4 source files, which are edited and compiled, and EX4 files, which are compiled programs intended for execution in MetaTrader 4. (MQL5)

So if you have:

MyExpert.ex4

but do not have:

MyExpert.mq4

you cannot normally open the EX4 in MetaEditor and edit its original MQL4 code like an MQ4 file.

This guide explains what you can do instead.


What Is an EX4 File?

An EX4 file is the compiled version of an MQL4 program.

The normal development process is:

MQ4 Source Code

       ↓

    Compile

       ↓

      EX4

       ↓

MetaTrader 4 executes it

The MQ4 file is the source code that developers work with.

The EX4 is the compiled program used by the terminal.

MetaQuotes documentation describes MQ4 as source code and EX4 as the compiled program created after compilation. (MQL5)


Can You Directly Edit an EX4?

Not in the normal MetaEditor workflow.

MetaEditor is designed for editing MQL4 source code.

For example, if you have:

MyEA.mq4

you can open the source, modify it and compile it again.

If you only have:

MyEA.ex4

there is no normal source-editing workflow that lets you open it and change the underlying MQL4 code directly.

MQL4 community guidance has consistently distinguished the editable MQ4 source from the compiled EX4 program. (MQL5)


Why Can’t You Just Open EX4 in MetaEditor?

Because compilation changes the source program into a compiled executable representation.

Think of the workflow as:

Human-readable source

        ↓

      Compiler

        ↓

Compiled executable

The compiler does not simply store the original MQ4 document inside the EX4 as an ordinary text file.

That means the original source may not be available when you receive only the EX4.


What If You Want to Change an EX4?

There are several possible situations.

Situation 1: You Have the MQ4

This is the easiest situation.

You can:

  1. Open the MQ4 in MetaEditor.
  2. Make your changes.
  3. Save the source.
  4. Compile it.
  5. Test the resulting EX4.

MetaQuotes’ documentation describes compilation as the process that turns MQL source code into an executable program. (MQL5)


Situation 2: You Only Have the EX4

If you only have the EX4, you do not have the normal editable source.

Your options become more limited.

You can:

  • identify the EA or indicator,
  • inspect its available inputs,
  • check its dependencies,
  • determine its MT4 environment,
  • obtain the original MQ4 from the developer,
  • or investigate whether authorized source-code recovery/reconstruction is technically possible.

The appropriate option depends on what you need to change.


Option 1: Ask the Original Developer for MQ4

If you purchased or commissioned the EA, the best solution is often to obtain the original source from the developer.

For example:

EX4

+

Original MQ4

Once the MQ4 is available, modifications can be made normally.

This also preserves the original development structure, comments, functions and dependencies where they are included in the project.


Option 2: Recover or Reconstruct Source Code

If the original MQ4 is genuinely unavailable, an authorized source-recovery project may be considered.

The goal should be described accurately as:

EX4 source-code recovery or reconstruction

rather than assuming that every EX4 can be converted into an identical original MQ4.

Possible objectives include:

  • recovering useful source-level logic,
  • reconstructing functionality,
  • understanding an old EA,
  • preparing an application for maintenance,
  • recreating specific features,
  • or rebuilding a compatible implementation.

The result depends heavily on the individual EX4.


What Can Source Recovery Potentially Provide?

Depending on the particular program, recovery may potentially help reconstruct things such as:

  • trading conditions
  • calculations
  • functions
  • inputs
  • order management
  • indicator logic
  • program structure

However, the resulting source should not automatically be considered identical to the original developer’s MQ4.


What May Be Lost?

Information that may not be reproduced exactly can include:

  • comments
  • formatting
  • original variable names
  • original function names
  • source-file organization
  • MQH files
  • EX4 libraries
  • external DLL functionality
  • server-side components

For example, the original developer may have used:

maximumDailyLoss

while a reconstructed version may use a different identifier.

The functionality can be the important part, rather than reproducing the exact original text.


What If the EX4 Uses DLLs?

This can make the project more complicated.

An MQL4 program can import functions from external DLLs. MetaQuotes documents DLL imports through the MQL4 #import mechanism. (MQL5)

A simplified structure could look like:

TradingEA.ex4

      ↓

External DLL

      ↓

Additional functionality

If important logic exists inside the DLL, recovering the EX4 alone will not automatically recreate the DLL’s internal source.

Therefore, if you have a DLL legitimately associated with your EA, preserve it as part of the project.


What If the EX4 Uses Other EX4 Libraries?

An EA can also depend on compiled EX4 libraries.

For example:

MainEA.ex4

     ↓

RiskLibrary.ex4

     ↓

SignalLibrary.ex4

MetaQuotes documents EX4 libraries as part of the MQL4 application structure. (MQL5)

If those dependencies are missing, the recovered or rebuilt program may not behave correctly.

For this reason, collect all related files before attempting a recovery project.


Can You Change EX4 Inputs Without Editing the File?

Sometimes you do not actually need to edit the EX4 itself.

Many Expert Advisors expose configurable inputs through the MT4 properties window.

For example:

LotSize = 0.10

StopLoss = 500

TakeProfit = 1000

MagicNumber = 12345

If these values are exposed as EA inputs, you may be able to change them directly when attaching the EA to a chart.

That is different from modifying the EA’s underlying program logic.


Editing Inputs vs Editing Logic

This distinction is important.

Changing an input

You might change:

LotSize = 0.10

to:

LotSize = 0.20

if the developer exposed that setting.

Changing the program logic

You might want to change:

Open trade when condition A occurs

to:

Open trade only when conditions A + B occur

The second change requires modifying the underlying program logic.

If you only have the EX4, you do not have the normal MQ4 source required for that type of modification.


Can You Change an EX4’s Name?

You may be able to rename the file for organizational purposes, but that does not modify its internal program logic.

For example:

OldEA.ex4

could potentially be renamed:

MyEA.ex4

but this does not turn it into an editable MQ4 or change what the program does.

The filename and the program’s internal code are separate things.


Can You Change the EA’s Settings?

If the developer exposed settings as external inputs, you can often modify those settings from MetaTrader 4 without modifying the EX4.

This can include things such as:

  • lot size
  • stop loss
  • take profit
  • risk percentage
  • trading hours
  • magic number
  • spread limits
  • indicator periods

The exact settings depend on how the EA was designed.


What If You Need a New Feature?

Suppose your EX4 works correctly but you want to add:

  • a new trading filter,
  • a new indicator,
  • a news filter,
  • different risk management,
  • additional alerts,
  • new entry conditions,
  • a different exit system.

If you have the MQ4, the developer can modify the source and compile a new EX4.

If you only have the EX4, the project becomes a source-recovery or redevelopment task rather than ordinary editing.


How EX4 Source Recovery Works at a High Level

A legitimate recovery project can generally be approached in stages.

Step 1 — Preserve the original

Keep the original EX4 untouched.

Step 2 — Identify the program

Determine whether it is an:

  • Expert Advisor
  • indicator
  • script
  • library

Step 3 — Identify dependencies

Look for:

  • EX4 libraries
  • DLLs
  • indicators
  • configuration files
  • SET files

Step 4 — Assess the file

Determine what type of recovery may be technically realistic.

Step 5 — Reconstruct the required source

Where possible, produce a usable source representation.

Step 6 — Compile

Compile the reconstructed MQ4 in the appropriate MQL4 environment.

Step 7 — Test

Compare the resulting program with the original under controlled conditions.


Why MT4 Build History Matters

MetaTrader 4 changed significantly beginning with Build 600.

MetaQuotes documented changes to the MQL4 language, MetaEditor, file structure and program handling during the Build 600 transition. (MQL5)

MetaQuotes also documented that old EX4 files were copied during the upgrade and were not automatically recompiled. (MQL5)

This means an older EX4 and a newer EX4 may have different technical histories.

If you are trying to recover source code, knowing the approximate build generation can therefore be useful.


What About Protected EX4 Files?

Some commercial EAs use additional protection mechanisms.

Protection can involve:

  • licensing
  • account restrictions
  • DLL dependencies
  • external validation
  • proprietary communication
  • anti-tampering systems

A protected EX4 should be assessed individually.

The presence of protection does not mean that the file should automatically be assumed to contain no useful information, but it can affect the technical scope of a legitimate recovery project.


How to Edit an EX4: The Practical Decision Tree

If you are asking:

“I want to change an input.”

Check the EA’s exposed settings first.

“I want to change the trading logic.”

You normally need the MQ4 source or an authorized source-recovery/redevelopment project.

“I want to add a new feature.”

You normally need editable source code.

“I lost my MQ4.”

Look for backups or contact the original developer. If unavailable, investigate authorized source recovery.

“The EA uses DLLs.”

Collect the DLL and all related files before assessing the project.


How to Edit MQ4 and Create a New EX4

Once you have legitimate MQ4 source, the normal workflow is straightforward:

Open MQ4

   ↓

Edit source

   ↓

Save

   ↓

Compile

   ↓

New EX4

   ↓

Test in MT4

MetaEditor provides the normal environment for editing and compiling MQL4 source. (MQL5)

If compilation produces errors, those errors need to be corrected in the source before the resulting EX4 can be considered ready.


Always Keep a Backup

Before modifying an MT4 project, keep separate copies of:

Original/

    MyEA.ex4


Source/

    MyEA.mq4


Libraries/

    *.ex4


DLL/

    *.dll


Settings/

    *.set

This makes it much easier to restore the original configuration if a modification causes unexpected behavior.


Test Before Using a Modified EA Live

Trading software should be tested carefully after source modifications or reconstruction.

A sensible progression is:

Compile → Backtest → Demo → Forward test → Live

Pay particular attention to:

  • entry conditions
  • exit conditions
  • position sizing
  • stop loss
  • take profit
  • spread filters
  • trading hours
  • broker-specific behavior
  • external dependencies

A program that compiles successfully is not automatically proven to behave exactly as intended.


Frequently Asked Questions

Can I edit an EX4 file directly?

Not through the normal MQL4 source-editing workflow. The editable source is the MQ4 file. (MQL5)

How do I edit an EX4?

If you have the original MQ4, edit the MQ4 and compile it again. If you only have EX4, you need the original source or an authorized recovery/redevelopment approach.

Can I convert EX4 back to MQ4?

Source recovery may be possible in some cases, but it should not be treated as a guaranteed conversion to the exact original source.

Can I change an EA’s settings without MQ4?

Often yes, if the developer exposed those settings as inputs in the EA.

Can I add features to an EX4?

Not through ordinary MetaEditor editing. You generally need editable source code or a legitimate redevelopment/recovery project.

Can I edit a DLL used by an EX4?

A DLL is a separate binary component. The DLL should be treated separately from the EX4, and you need appropriate authorization to modify it.

Will recovered MQ4 be identical to the original?

Not necessarily. A recovered source representation can differ from the original developer’s source.


Final Takeaway

If you only have an EX4 file, you should first determine what kind of change you actually want to make.

If you only need to adjust exposed settings, you may be able to do that directly from MetaTrader 4.

If you need to change the actual trading logic, add features, modify calculations, or repair the program, the normal route is to obtain the MQ4 source code.

If the MQ4 has been lost, an authorized EX4-to-MQ4 source-code recovery or redevelopment project may be considered, but the result depends on the specific EX4 and its dependencies.

The basic rule is:

MQ4 = source you edit

EX4 = compiled program you run

EX4 → MQ4 = source recovery/reconstruction, not ordinary editing.