3 February 2014
3 February 2014
Over the past 7 months since the release
of the public build 509, we put in a lot of effort to improve MetaTrader
4 client terminal. MQL4 programming language for developing trading
strategies has undergone the most significant changes - program
execution speed has been increased, while the language itself has been
brought closer to MQL5 to the maximum possible extent. This means that
MQL4 trading robot developers can now also enjoy all the advantages of
OOP: classes and structures, inheritance, Standard Library, resources and much more.
New MetaEditor provides such features as debugging, profiling, personal storage, autosubstitution of function names, snippets, inserting resources and intelligent code management.
The new MetaTrader 4 terminal features the Market - store of protected applications for MetaTrader 4 terminal. Now, any
developer can put his or her own trading programs for sale on the
unified application store, while traders can buy any product right from
the terminal. All EX4 application files downloaded from the Market have
the high level of protection similar to that of MQL5. MQL4 application
developers can set the number of activations and prices for their
products without worrying about the technical issues related to sales
process - MetaTrader 4 Market will take care about the latter.
Due to changes in the file structure and location of the directory for storing custom files (indicators, Expert Advisors, scripts, templates, logs, etc.), all these data will be automatically moved to the new place during the update. Not a single custom file will be deleted during the process, and all original files will remain in their appropriate locations becoming backup copies.
Microsoft Windows XP released 13 years ago allows applications to write their own data at the place of their installation even if the latter took place in Program Files system folder. A user should only have an administrator permission to write data to any folder.
Starting from Windows Vista, Microsoft has introduced a restriction on writing to Program Files directory. If User Account Control
(UAC) system is enabled, programs are not allowed to store their data
in Program Files folder. All data should be located in a separate user
directory. This limitation has been introduced in order to protect users
against malicious programs and to prevent applications under one user
account to change or damage the same program's data necessary for
another user account. Since that time, security requirements in
Microsoft operating systems have been tightening further. In particular,
starting with Windows 8, UAC system cannot be disabled even if "Never
notify" option is selected in its settings.
Microsoft has implemented virtualization process in order to provide compatibility with older applications when using UAC. If a program tries to save its data to Program Files directory, the data is actually (physically) saved to a separate folder having the following look - C:\Users\<user-name>\AppData\Local\VirtualStore\Program Files, while Windows File Explorer shows the files as if they are saved in the installation directory. Microsoft claims that this mode has been provided only for compatibility and can be removed later.
In order to comply with Microsoft recommendations, the data storage structure has been changed in MetaTrader 4 client terminal starting from build 600. Now, the terminal will also save its data in a user directory.
In the new version, all data of a certain user working with a certain
copy of MetaTrader 4 terminal are stored in a special place called terminal data folder. This folder can be found on a system disk (a disk with installed Windows operating system) along the following path
C:\Users\User_account_name\AppData\Roaming\MetaQuotes\Terminal\Instance_idwhere:
"Open Data Folder" command has been added to File menu of the terminal for searching and opening the data folder.
The root of each terminal data folder also contains origin.txt file where you can find the path to the installation folder of the terminal this data refers to. This allows users to match each terminal data folder with a certain terminal installation directory, for example, in case when several copies of MetaTrader 4 terminal are installed by a user. This type of working with the terminal when the data folder is separated from the installation one is the main mode.
For more convenience, an entry containing the path to the data folder is made in the terminal's journal each time the terminal is launched. For example:
2014.02.10 12:48:28.477 Data Folder: C:\Users\JohnSmith\AppData\Roaming\MetaQuotes\Terminal\9F86138A4E27C7218E9EC98A5F8D8CA1
When the newly updated terminal is launched, it checks if the data folder is present. If the data folder is not present yet, then it is created. If that folder is different from the installation one, the terminal's regular data (standard MQL4 programs, historical data, configuration files, templates, etc.) is copied into it. The files that are not changed during the terminal operation (executable files, mql.dll compiler, sound files, etc.) are left in the installation directory. The terminal data folder is different from the installation one in the following cases:
If none of the above conditions is satisfied, the terminal data is stored in the installation directory.
Then, the user files are moved to the data folder. At this stage, the directory where the terminal's user data has been stored is determined. If the data has been stored in the terminal installation folder, they are copied the following way:
Source folder in the installation directory |
Contents | Destination folder in the terminal data directory |
---|---|---|
\experts |
Expert Advisors (trading robots) Note: only files from the root \experts directory are copied. No subdirectories are copied, since it is impossible to reliably determine their contents |
\MQL4\Experts |
\experts\indicators | Custom indicators |
\MQL4\Indicators |
\experts\scripts |
Scripts (MQL4 applications for a single run on the chart) | \MQL4\Scripts |
experts\include | Source code MQH and MQ4 files implemented into other programs | \MQL4\Include |
experts\libraries | Libraries in the form of MQ4 source codes and EX4 executable files compiled from them. They are used for the dynamic call of the functions contained there by other MQL4 programs | \MQL4\Libraries |
experts\files | Special "file sandbox". MQL4 applications are allowed to execute file operations only within this directory | \MQL4\Files |
experts\logs |
Log files of MQL4 applications |
\MQL4\Logs |
experts\presets |
Files of presets for MQL4 applications |
\MQL4\Presets |
experts\images |
Image files for being used in resources | \MQL4\Images |
Next, it is checked whether the client terminal has stored data in virtualization directory (the operating system's virtual storage described above). If the terminal has been installed in Program Files directory and the operating system is Windows Vista or higher, the terminal data is most probably stored in that directory. If the data is found, it is copied according to the above table.
During the migration, the entries containing source and destination
paths of the copied files are made in the terminal's journal. To view
all the logs, open Journal tab of Terminal window and execute Open
command in the context menu. The folder containing the terminal log
files will open.
If the migration has been completed successfully for the current terminal copy, it is not repeated any more during subsequent MetaTrader 4 terminal updates. If the data folder is different from the installation one, and custom MQL4 applications have been copied together with the standard files during the migration, the following dialog window appears:
Portable launch mode is provided for the terminal operation on portable devices and non-system directories, as well as for working in Windows XP. When launched in this mode, the terminal tries to save its data in the installation folder. However, using Portable mode does not guarantee that an operating system will allow storing data in the installation folder (for example, if the terminal is installed in Program Files directory and UAC system is enabled).
The following conditions should be met for working in Portable mode:
Installation directory |
Operating system |
Requirements |
---|---|---|
Program Files or another system directory (for example, Windows) |
Windows XP |
Permission to write to the installation folder |
Another non-system directory |
Windows XP |
Permission to write to the installation folder |
External hard drive, usb flash drive, etc. | Windows XP | The terminal will always be launched in Portable mode. |
Program Files or another system directory (for example, Windows) | Windows Vista\Windows 7 |
Launching the terminal as administrator and disabled UAC |
Another non-system directory | Windows Vista\Windows 7 |
Permission to write to the installation folder |
External hard drive, usb flash drive, etc. | Windows Vista\Windows 7 | The terminal will always be launched in Portable mode. |
Program Files or another system directory (for example, Windows) |
Windows 8 and higher |
It is impossible to use Portable mode, as UAC system cannot be disabled |
Another non-system directory | Windows 8 and higher |
Permission to write to the installation folder |
External hard drive, usb flash drive, etc. | Windows 8 and higher | The terminal will always be launched in Portable mode. |
In order to launch the terminal in Portable mode, use "/portable" key. For more convenience, you can create an additional terminal launch shortcut with the appropriate name on your desktop and add the key directly to the shortcut:
struct RateInfo { unsigned int ctm; // bar open date double open; // Open price double low; // Low price double high; // High price double close;// Close price double vol; // volume };
In the new format, RateInfo structure features fields for storing spread and trading volume:
//--- Standard quote presentation in the new terminal version struct RateInfo { INT64 ctm; // open date and time double open; // Open price (absolute value) double high; // Low price double low; // High price double close; // Close price UINT64 vol; // tick volume INT32 spread; // spread UINT64 real; // trade volume };
Thus, if MQL4 programs contain DLLs for passing/accepting price data, the corresponding functions in the source codes should be rewritten and recompiled considering format changes to ensure proper operation.
Fixed errors reported on the forum and in crash logs.
MQL4 programming language has been completely revised reaching the level of MQL5 - now you can develop trading robots in MQL4/5 using the unified MetaEditor development environment, single style, libraries and debugging tools.
MQL4 is popular among automated system developers due to the ease of learning and a huge amount of code generated for many years of using MetaTrader 4 terminal. However, the language also has some drawbacks arising from its main advantage - a simple programming language does not allow development of complex systems and hinders porting of debugged libraries from high-level languages. Therefore, we decided to implement in it the maximum possible amount of MQL5 language functions and features fully preserving MQL4 functionality. In other words, all powerful MQL5 functions, including ООP and the native code compiler, will become available in MQL4.
To achieve this, we have developed a unified compiler that automatically supports both MQL4 and MQL5 languages. MetaEditor will also become a unified application both for MetaTrader 4 and MetaTrader 5 platforms. Thus, it will be possible to compile both MQL4 and MQL5 from any version. MQL5 Storage also becomes available for work.
Protection of MQL4 applications rises to MQL5 level. New EX4/EX5 files are provided with a serious and completely revised protection. This means that the Market of secure EX4 applications also becomes available to MetaTrader 4.
Besides, MQL4 now features new graphical objects and new functions
for working with charts. MQL5 Standard Library is to be ported to MQL4
providing developers with new possibilities in creating their own
graphical interfaces and trading libraries. Now, you can create
full-fledged applications in MetaTrader 4 using the resources.
Changes in MQL4 Language
if(condition1 && condition2) { // some block of operations }If condition1 expression is false, calculation of condition2 expression is not performed, as false && true result is still equal to false.
#property strict
The table of differences between compilers
Old MQL4 compiler |
New MQL4 compiler |
New MQL4 with #property strict |
---|---|---|
init(), start() and deinit() entry points may have any parameters and any return type | init(), start() and deinit() left intact for the sake of compatibility and new OnInit(), OnStart(), OnCalculated, OnTick(), OnTimer(), OnChartEvent(), OnTester() and OnDeinit() should exactly match their signatures |
|
Virtually any variable names (except for the reserved words) are possible, including special characters and points |
Variable names cannot have special characters and points. The list of the reserved words has been expanded. Thus, such widespread words as short, long, const, etc. cannot be used as names |
|
Variable scope is from declaration (even in the nested block) to the function end |
Variable scope is from declaration to the end of the block, in which the variable is declared |
|
Implicit initialization of all the variables (both global and local ones) by zero |
Only global variables are initialized. Only strings are initialized implicitly in local variables. |
|
Local arrays are not released when exiting the function |
Local arrays are released when exiting the function |
Local arrays are released when exiting {} block |
"Array out of range" does not cause a critical error * |
Ditto, except for the arrays of structures and classes, for which this error is critical one |
"Array out of range" is a critical error causing the program to stop |
No structures and classes |
Structures and classes are present. Additional data types are implemented |
|
Strings are single-byte. datetime is a 32-bit integer. Predefined Volume variable is of double type |
Strings are unicode ones. datetime is a 64-bit integer. Predefined Volume variable is of ulong type |
|
ArrayCopyRates() performs virtual copying to double[][6] array | ArrayCopyRates() performs virtual copying to MqlRates[] array. Copying to double[][6] array has remained intact for the sake of compatibility, however, that copying is real, not virtual | |
The functions may not return values even if they
have a type. To do this, return(0) is automatically inserted by the
compiler in the function end |
Functions of any type should return a value |
|
The number of simultaneously opened files is 32 |
The number of simultaneously opened files is 64 |
|
The files are always opened in shared use mode ** |
Shared use mode should be specified explicitly using FILE_SHARE_READ and/or FILE_SHARE_WRITE |
* Please pay special attention to "Array out of range" error
- many old custom indicators will display this error in strict mode of
the new compiler when launched on the chart. It is recommended to find
the cause and eliminate it.
** In the new MQL4 and MQL5, FILE_SHARE_READ and FILE_SHARE_WRITE flags are responsible for the files shared use mode. There were no such files in the old MQL4.