Discussion of article "Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#)"

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
201461
MetaQuotes Software Corp.  

New article Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#) has been published:

The article describes how to add the ability to work with Microsoft SQL Server database server to MQL5-based Expert Advisors. Import of functions from a DLL is used. The DLL is created using the Microsoft .NET platform and the C# language. The methods used in the article are also suitable for experts written in MQL4, with minor adjustments.

Questions related to integrating the work with databased into Expert Advisors written in MQL5 often appear on the forums. Interest in this topic is not surprising. Databases are very good as a means of saving data. Unlike the terminal logs, the data do not disappear from the databases. They are easy to sort and filter, choosing only the required ones. A database can be used to pass the necessary information to an expert — for example, certain commands. And most importantly — the obtained data can be analyzed from different perspectives and processed statistically. For example, writing a one-line query is enough to find out the average and total profit for a specified time for each currency pair. And now imagine how long it takes to manually calculate this for the account history in the trading terminal.

Unfortunately, MetaTrader does not provide built-in tools for interacting with database servers. The problem can only be solved by importing functions from DLL files. The task is not simple, but feasible.

Start the expert, changing the connection string values to your database server access parameters. If everything is done correctly, the expert will output the following to the log:

2018.07.10 20:36:21.428    MqlSqlDemo (EURUSD,H1)    Connected to database.
2018.07.10 20:36:22.187    MqlSqlDemo (EURUSD,H1)    Created table in database.
2018.07.10 20:36:22.427    MqlSqlDemo (EURUSD,H1)    Data written to table.
2018.07.10 20:36:22.569    MqlSqlDemo (EURUSD,H1)    Number read from database: 1
2018.07.10 20:36:22.586    MqlSqlDemo (EURUSD,H1)    String read from database: Test

Connecting to the database, executing SQL commands, writing and reading data — everything is executed successfully.

Author: Сергей Ткаченко

Pawel Michalowski
185
Pawel Michalowski  
Amazing article! Exactly what I was looking for! Thank you Sergiey!
To add comments, please log in or register