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

 

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: Сергей Ткаченко

 
Amazing article! Exactly what I was looking for! Thank you Sergiey!
 
Yes, very nice work Sergy, much appreciated. 
 

Love the article - thanks very much for the in-depth discussion.


Hoping someone can help me with a snag during Build time.

C:\Users\user\source\repos\mql\MqlSqlDemo\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error : Microsoft.Build.Utilities.ToolLocationHelper could not find ildasm.exe


Essentially, the UnmanagedExports utility is unable to find the disassembler executable required to perform it's work.


I know for a fact that ildasm.exe exists, and it's various locations... but not sure how to get DllExport to recognize the proper path.
 
Superb Article !!! Thanks for explaining the nitty-gritty details as well as for providing the downloadable files. Will try to implement this myself. Thanks a lot !!! Well wishes & Kudos!
 

Hello I have tried the dll. And works!

I would like to test the complete library. That you could upload it again? (https://bitbucket.org links are broken?)

Thank you!

Bitbucket | The Git solution for professional teams
Bitbucket | The Git solution for professional teams
  • Atlassian
  • bitbucket.org
Collaborate on code with inline comments and pull requests. Manage and share your Git repositories to build and ship software, as a team.