Sharing Database Between MT5 Instances

 

I am using this article to make an automated optimization process for my EA. 

https://www.mql5.com/en/articles/4917

While the author exports the optimization results as an xml file which is read by the “Working Instance”, I am taking a different approach. My EA will log all deals into a database at the end of each pass. 

The problem is I want this database to be accessible by both the Working Instance and the Optimiser Instance.


Can sqlite files be stored in the common folder for multiple terminals to read / write ?

Can a single database be accessed at the same time from multiple terminals?

Any suggestions for my approach?

 
emerson2102:

I am using this article to make an automated optimization process for my EA. 

https://www.mql5.com/en/articles/4917

While the author exports the optimization results as an xml file which is read by the “Working Instance”, I am taking a different approach. My EA will log all deals into a database at the end of each pass. 

The problem is I want this database to be accessible by both the Working Instance and the Optimiser Instance.


Can sqlite files be stored in the common folder for multiple terminals to read / write ?

Can a single database be accessed at the same time from multiple terminals?

Any suggestions for my approach?

I have never use SQLite with MetaTrader, but the SQLite engine can support concurrent access to a degree, if done properly.

Read up on the following Article, which also includes a section on saveing optimisation results to be used afterwards:

SQLite: Native handling of SQL databases in MQL5
SQLite: Native handling of SQL databases in MQL5
  • www.mql5.com
The development of trading strategies is associated with handling large amounts of data. Now, you are able to work with databases using SQL queries based on SQLite directly in MQL5. An important feature of this engine is that the entire database is placed in a single file located on a user's PC.
 
emerson2102: Can sqlite files be stored in the common folder for multiple terminals to read / write ?

Followup: Even if MetaTrader does not allow the SQLite file to be placed in a common area, you can still use a hard-link at the various locations, so as to point to a common location, and have the database be shared and accessible to both the Strategy Tester and the working EA.

 
Fernando Carreiro:

Followup: Even if MetaTrader does not allow the SQLite file to be placed in a common area, you can still use a hard-link at the various locations, so as to point to a common location, and have the database be shared and accessible to both the Strategy Tester and the working EA.

Thank you very much! I missed a very obvious piece of information in the DatabaseOpen() doc...

https://www.mql5.com/en/docs/database/databaseopen

there is a DATABASE_OPEN_COMMON flag...

I did some testing and found that databases stored in common can be opened, read, and written to simultaneously by separate terminals. Although I am not sure how safe it would be to read / write to the same table. That is why I will be modifying different tables from each terminal.

Documentation on MQL5: Working with databases / DatabaseOpen
Documentation on MQL5: Working with databases / DatabaseOpen
  • www.mql5.com
DatabaseOpen - Working with databases - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
emerson2102:

Thank you very much! I missed a very obvious piece of information in the DatabaseOpen() doc...

https://www.mql5.com/en/docs/database/databaseopen

there is a DATABASE_OPEN_COMMON flag...

I did some testing and found that databases stored in common can be opened, read, and written to simultaneously by separate terminals. Although I am not sure how safe it would be to read / write to the same table. That is why I will be modifying different tables from each terminal.

Thank you for the update!
 
emerson2102 #:

Thank you very much! I missed a very obvious piece of information in the DatabaseOpen() doc...

https://www.mql5.com/en/docs/database/databaseopen

there is a DATABASE_OPEN_COMMON flag...

I did some testing and found that databases stored in common can be opened, read, and written to simultaneously by separate terminals. Although I am not sure how safe it would be to read / write to the same table. That is why I will be modifying different tables from each terminal.

@emerson2102 thank you for your comment. The DATABASE_OPEN_COMMON is to define which folder the file is created (see below), but it does not say it supports concurrency. Can you please share if your experience in using same db file simultaneously? Thanks

DATABASE_OPEN_COMMON

The file is in the common folder of all terminals

Reason: