Skip to content
Next

Advanced MT4 Features & MetaEditor

In this lesson we will examine:

– Advanced functions and features of MetaTrader 4
– Different file types used by MetaTrader 4
– How to develop your own custom indicators, EAs and scripts using MetaEditor

Welcome to our Advanced Course. In the Basic and Intermediate courses, we looked at the basic features of MetaTrader 4 and many aspects related to trading and different financial markets.

In this Course, we will look at more advanced features of the MetaTrader 4 platform, and examine how these features can be used to develop and backtest your own automated trading system, using Expert Advisors (EAs), or your own manual trading system.

In this lesson, we will look at some important features and functions that will be useful information for the other chapters in this Course.

MQL4 & Other File Types

First, let’s look at the different file types used by the MT4 platform. The main file type in MT4 is .mq4, which are files generated by MetaQuotes Language 4 (MQL4).

MQL4 is an integrated programming language for developing trading strategies for the MT4 platform. It allows you, or a developer you hire, to create your own technical indicators, EAs, scripts, and function libraries for your own trading systems.

MQL4 is similar to the С++ programming language, providing an object-oriented development platform. With MQL4, you can develop complex programs with a large number of calculations and include a vast array of parameters and logic within you Expert Advisors and indicators.

MQL4 provides many functions for analyzing current and previously received price quotes, and has built-in basic indicators and functions for placing orders and managing trades.

MQL4 provides the ability to create four different kinds of tools:

Custom Indicators

As we have seen in previous lessons, custom indicators are tools for technical analysis of the market. They could be based on standard indicators, such as MACD, or they could be a combination of different indicators that only show signals when the conditions for the variables you have chosen are met. We will examine developing your own custom indicators for creating your own trade signals in more detail in the next lesson.

Expert Advisors

Also known as “Trading Robots”, “Algorithmic Trading Bots”, “Algos” and others, Expert Advisors are applications that can be programmed to analyze the market and place trades automatically, semi-automatically or just to produce signals for manual trading. You can also develop EAs to manage trades you have placed yourself, for example to automate your trailing stops. We will examine EAs in more detail later in this course.

Scripts

Scripts are tools that allow you to perform tasks and save time. For example, a script could be used to delete all objects from the chart or close all orders. More advanced scripts can be used to generate offline charts, which allow you to use non-standard chart types. We will look at offline charts in more detail in a future lesson.

Libraries

A library is a set of custom functions. It is intended to store and distribute algorithms that are commonly used in custom applications. Libraries are small sub-programs that can be used for developing new applications. They do not execute trading or analytical functions and cannot be run in MetaTrader 4. Their purpose is to simplify development of new applications in MQL4.

File Types

In MQL4, there are three types of files that can be utilized: MQ4, EX4, and MQH. A fourth type of file is also used, called DLL files, but these aren’t created using MetaEditor.

MQ4 Files

MQ4 files are program source code generated by MetaEditor. Files of this type contain source code for all types of files usable in the MT4 platform (EAs, scripts, indicators). For the creation of program codes, MetaEditor is used. When a code is fully or partially created, it can be saved and later opened for modification. Files of .mq4 type cannot be used for execution in the client terminal. Instead, a .mq4 file must be compiled first before you can use it.

EX4 Files

An EX4 file is a compiled program ready for practical use in the client terminal. Files of this type cannot be edited, unless you have the original .mq4 file as well. The .mq4 file is edited and then compiled into .ex4 format again. The .ex4 file type is used for indicator, EAs and scripts, and can also be used as Library files.

MQH Files

Files of .mqh type are “Include” files. It is a source text of frequently used blocks of custom programs. Include files are called so because they are usually “included” at the stage of compilation to the main source file using the #include directive. .mqh files can be included into source texts of EAs, scripts, and indicators at the stage of compilation.

Despite the fact that files of .mqh type can contain a program source code and can be compiled by MetaEditor, they are not independent and self-contained, that is they do not require compilation for getting executable files of .ex4 type.

SET Files

Files of .set type are mostly used by traders to save the parameters of their Expert Advisor optimizations and backtests. By default, these are saved in the “tester” folder. When loading .set files into an EA that is on a chart, the MQL4 > Presets folder is the default.

HST Files

Files of .hst type are history files that are used to generate charts. These files are stored in the history > broker folder.

FXT Files

Files of .fxt type are history files that are used to generate backtesting data for the MT4 Strategy Tester. These files are stored in the tester > history folder.

TPL Files

Files of .tpl type are used to save and load templates to your chart, as we looked at in a previous lesson. These are stored in the “templates” folder.

DLL Files

Dynamic-Linked Library (DLL) files are normally written using C or C++, using programs such as Visual Studio.

The reason .dll files are required for certain indicators is to allow MetaTrader to extend its functionalities and utilize certain Windows features. The .dll allows an indicator to complete tasks which MetaTrader can’t normally perform.

In short, an indicator’s .dll file extends the functionality of MT4.

However, .dll files can be used as malicious software. If you’re installing a .dll for MT4, make sure it is from a reputable source or coder. Also be aware that most commercial MT4 software utilizes .dll files for preventing piracy – often holding code that communicates with a server to validate that the user has purchased the software. This type of .dll will frequently generate false-positives from anti-virus software.

To enable .dll files for Expert Advisors in MT4, simply hold the “Ctrl” button on your keyboard and press “O”; this brings up the Options context menu. Select the “Expert Advisors” tab and the enable the checkbox for “Allow DLL imports”:

File System

We will now examine how to locate the folders within MT4 for some of these different file types. Select “File” from the top menu and then click “Open Data Folder”:

All the relevant folders for your MT4 platform and Terminal are now shown. All the relevant files are used by sub-folders inside the MQL4 folder:

 

You will then see the following folders:

As outlined above, .mq4 and .ex4 files can be used in the Experts, Indicators, Libraries and Scripts folders.

.mqh files can be found in the Libraries folder (for example, stdlib.mqh) or the Include folder (for example, stderror.mqh or WinUser.mqh).

Finally, any .dll files would always be placed in the Libraries folder.

MetaEditor

MQL4 programs are developed in the built-in MetaEditor.  It is a convenient and versatile tool for developing Expert Advisors, custom indicators, scripts and libraries of any complexity which are then used in the platform. Ready-made applications automatically appear in MetaTrader 4 and can be launched immediately.

MetaEditor recognizes various patterns of the language. It suggests tips on how to use functions and highlights various elements of the program source code. Thus, the editor enhances navigation in the source code of trading programs and speeds up the development process.

The built-in debugger and code profiler make the development much easier. The debugger finds and eliminates errors, while the profiler detects the slowest parts of the code and optimizes the program operation.

Launching MetaEditor

The fastest way to launch MetaEditor is to simply tap the F4 key on your keyboard when MT4 is open.

Using the Navigator you can edit any existing .mq4 files installed in your MT4 terminal.

Alternatively you can create new projects either by right-clicking in the Navigator using your mouse as shown below:

or by selecting File from the top menu:

Developing Your Own Custom Programs

If you already have some aptitude in programming languages, you can learn more about the language using the official MQL4 Tutorial

If you are unable to code or don’t have the time to learn, you can hire developers from the Freelance section of the MQL5.com website, or other freelance websites such as Fiverr.com

Please note we are not responsible for content on third-party websites, it is your responsibility to conduct due diligence on any freelance developer you may choose to hire for your project.

Note: It is important to ensure that you always receive the final code in .mq4 format. This allows you to continue development in case you need to work with a different programmer in future. If you only have the .ex4 file, you will likely have to develop the entire project again from scratch if you need to make modifications.