MetaEditor provides options for convenient operations with databases. These capabilities are implemented based on the popular SQLite engine integration. The entire database is located in a single file on a user PC's hard disk.
The editor provides access to the main functions for working with databases, allowing you to:
The development of trading strategies is associated with processing of large amounts of data, and that is why databases are widely used in algo trading. The usage of databases will enable you to:
The MQL5 language supports functions for working with databases directly from your programs. For details please read the article "SQLite: Native handling of SQL databases in MQL5". |
The quick database creation functionality is available from the MQL5 Wizard. You can easily create your first table and define its fields.
The following field types are available:
Fields can also be marked with flags:
You can also create databases by using the Navigator context menu:
Once the database is created, you will be redirected to the appropriate Navigator section. All data operations are performed from this section.
You can create tables in a database based on ready-made CSV-files. Click "Import Table" in the database menu, select a file and set the following parameters:
The Navigator provides a separate tab for working with databases. Click "Open" in its context menu or in the "File" menu, and select the database file. Appropriate tables will appear in the Navigator.
Double-click on the table name to quickly query the first 1,000 records.
To execute a database query, enter it in the right part of the editor and click "Execute". In case of a query error, the corresponding message will be added to the log. An example of a simple query creating a table:
CREATE TABLE COMPANY(ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL); |
The COMPANY table has 5 fields: Record ID, Name, Age, Address and Salary. The ID field serves as a key. The key enables unique identification of each record and it can be used in different tables to link them together. This is similar to how a position ID links all deals and orders related to a particular position.
If a table column contains time data specified in minutes (UNIX time), seconds or microseconds since 1970.01.01, left-click on it and select the required format. After that, the time will be displayed in the usual format, YYYY.MM.DD hh:mm:ss.
To save a table as a file, query all data from the table using a query "SELECT * FROM [table name]", and then click "Export" in the context menu. The export operation provides the same table options as import.