Learning MetaTrader MQL5 File Types

When developing in MQL5 for MetaTrader 5, you’ll encounter several distinct MQL5 file types, each serving a unique purpose in the creation and execution of trading tools. In this article you can learn the differences between the MQL5 file types to better manage your projects and streamline your development process.

Understanding MetaTrader MQL5 File Types

Key MQL5 File Types

By now you should have some of the basic understanding of Metatrader, Metaeditor, Program Types and Folders.

The official documentation here covers programs types but I didn’t find the file types…

The next step is to understand the different MQL5 file types you can encounter, or create, with MetaEditor.

This table is a good summary of the file types and their main characteristics, we will then see each one with more details.

File TypeExtensionPurposeUsage
Source Code File.mq5Contains the actual MQL5 programming codeEAs, indicators, scripts
Executable File.ex5Compiled version of .mq5 or library filesRuns on MetaTrader 5
Include File.mqhReusable code snippets or configurationsShared between programs
Library File.ex5Precompiled reusable functions and logicCalled by other programs
Header File.mqhDefines constants, classes, and functionsWorks with .mq5 files
Resource File.bmp, .png, .csv, .txtExternal files like images or dataVisuals and data storage

Let’s take a closer look at each of these.

.mq5 – MQL5 Source Code Files

.mq5 files are the foundation of any MQL5 project.

These files contain the raw, human-readable source code for Expert Advisors (EAs), indicators, and scripts.

This is where the logic of your trading tools is written and modified.

Common Uses:

  • Writing automated trading strategies
  • Developing custom indicators for market analysis
  • Creating scripts for one-time tasks like order placement

The .mq5 file is crucial for development because it’s the file you write and edit directly in MetaEditor.

.mq5 files can be opened and read with both MetaEditor or any other text editor like Notepad, Notepad++ or VS Code.

To open .mq5 files, I recommend to not open it with a double click, but rather opening MetaEditor first and from within MetaEditor opening the mq5 file.

After writing, you’ll compile this file into its .ex5 form for execution.

.ex5 – Compiled Executable Files

.ex5 files are the compiled version of .mq5 files, turning your source code into machine-readable code that MetaTrader 5 can execute.

These files are essential for running your programs without exposing your source code.

Common Uses:

  • Running EAs and indicators on live or demo accounts
  • Protecting your code from unauthorized modification

Once compiled, .ex5 files cannot be edited, you would have to modify the original .mq5 file and recompile it if you need changes.

If you try to open .ex5 files with a text editor the content would be not legible

.mqh – Include and Header Files

.mqh files serve as supporting files, often containing reusable code snippets, shared functions, and configurations.

These files help keep your main .mq5 files clean and modular.

Common Uses:

  • Defining common functions shared between multiple .mq5 files
  • Organizing complex code into modular sections

Including .mqh files allows you to reuse code across multiple projects, saving time and reducing redundancy.

.mqh files can be opened and read with both MetaEditor or any other text editor like Notepad, Notepad++ or VS Code, same as .mq5 files.

.ex5 – Library Files

Though they share the .ex5 extension with executable files, libraries contain precompiled, reusable functions.

These libraries can be called by EAs, indicators, or scripts without exposing the source code.

Common Uses:

  • Advanced mathematical functions
  • Reusable trading logic

Libraries improve efficiency by allowing you to package frequently used functions in a precompiled format, speeding up execution time.

Resource Files (.bmp, .png, .csv, .txt)

Resource files support your MQL5 programs with external data or visual enhancements. These files provide additional functionality without being part of the main code.

Common Uses:

  • Custom icons for indicators
  • Data files for backtesting
  • Text files for logging and configuration

Using resource files keeps your code cleaner and allows for easier updates to visual elements or external data without recompiling.

Why Understanding File Types Matters

Knowing which file type to use and when is crucial for efficient MQL5 development.

Using the right file type helps you:

  • Organize your projects: Keeping different files for different purposes ensures cleaner project structures.
  • Protect your work: Compiling into .ex5 files keeps your source code safe.
  • Enhance reusability: Include files and libraries prevent code duplication and simplify maintenance.
  • Improve performance: Precompiled libraries can speed up execution by reducing runtime processing.

While at the beginning of your MT5 and MQL5 trading automation journey you might not use all of the file types, it is still important to understand what they are and their use.

In general, as a trader you will often find free or paid tools that will be downloadable in their .ex5 format, meaning you will not be able to know the source code, or make changes.

As you progress and learn more you will probably start creating your own .mq5 files.

Ultimately, once you become more advanced and create more complex tools, you will also leverage all the other types like .mqh and resource files.

Conclusion

Understanding MQL5 file types is essential if you are interested in using, or creating, MT5 automation tools. By using the right file for the right purpose, you ensure cleaner, more maintainable, and more powerful trading tools.

Organize your work well, take advantage of reusable code, and protect your intellectual property with the right file structure.

For any feedback or question please Contact Us.

How to Run MetaTrader MT5 Portable

Finding MT5 Config Files Location

Leave a Comment