MQL4 Book  MetaEditor  File System

File system


The client terminal recognizes program types by their location in subordinate directories.

All application programs are concentrated in the directory ClientTerminal_folder\experts. EAs, scripts, and custom indicators that you are going to use in your practical work should be located in corresponding directories, as shown in the Figure 24 following. EAs are located right in the directory ClientTerminal_folder\experts. Scripts and indicators are in subdirectories ClientTerminal_folder\experts\scripts and ClientTerminal_folder \experts\indicators, respectively.

Fig. 24. Directory for storing files, created by a user.

Figure 24 Directory for storing files, created by a user.

You can create other directories for storing some files. However, you cannot use programs located there.


File types

In MQL4, there are three types of files that carry a program code: mq4, ex4, and mqh.

Files of mq4 type represent a program source code. Files of this type contain source texts of all types of programs (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. A program must be compiled before you can use it. As a result of a source code compilation, a file of the same name with the extension ex4 is created.

A file of ex4 type is a compiled program ready for practical use in the client terminal. Files of this type cannot be edited. If a program needs to be modified, this should be done in its source code (a file of mq4 type); it should be edited and then compiled again. The ex4 file name does not point to the program type—whether it is a script, an EA, or an indicator. Files with ex4 extension can be used as library files.

Files of mqh type are include files. It is a source text of frequently used blocks of custom programs. Such files can be included into source texts of EAs, scripts, and indicators at the stage of compilation. Usually include files contain the description of imported functions (for example, see files stdlib.mqh or WinUser32.mqh) or the description of common constants and variables (stderror.mqh or WinUser.mqh). As a rule, files of mqh type are stored in the directory ClientTerminal_folder\experts\include.

Include files are called so because they are usually "included" at the stage of compilation to the main source file using the #include directive. 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. As include files, one can use mq4 files that should be stored in ClientTerminal_folder\experts\include.

Sections "EAs," "Custom indicators," and "Scripts" of the client terminal navigator will show only the names of files that have the extension ex4 and are located in the corresponding folder. Files compiled in older versions of MetaEditor cannot be started and are displayed in a grey color.

There are other types of files that do not make a complete program, but are used in the creation of application programs. For example, a program can be created out of several separate files or using a library created earlier. You can create libraries of custom functions intended for storing frequently used blocks of user programs. It is recommended to store libraries in the directory ClientTerminal_folder\experts\libraries. Files of mq4 and ex4 can be used as library files. Libraries cannot start by themselves. Using include files is more preferable than using libraries because of additional consumption of computer resources at library function calls.

In the first part of the book "Programming in MQL4," we analyze mq4 files of source texts and compiled ex4 files.