DataBase help needed..... Reduce lagtime and slippage....

 

I need some help from an experienced developer.

I would like to do the following:

1. Create a database in memory in "OnTick".

2. Do one query from defined StartTime to Timecurrent() and copy all the transactions to above database.

    Benefit is much less interaction with main server, less lag and much less slippage.

3. Do all my normal queries on the above database on the local PC/Server in stead of doing multiple queries to the trading server.

4. After 3 - then place the necessary trades, Stop losses etc.

5. Delete the database.... and start over at 1....


When browsing through the forums, all I see are loops, doing multiple single queries..... e.g.

 for(int pos= PositionsTotal(); pos>=0; pos--)

 .......

When speed and lag is important, the above method is highly inefficient.

Any help and sample code is greatly appreciated.

Thanks.

 
StarBuck99:

I need some help from an experienced developer.

I would like to do the following:

1. Create a database in memory in "OnTick".

2. Do one query from defined StartTime to Timecurrent() and copy all the transactions to above database.

    Benefit is much less interaction with main server, less lag and much less slippage.

3. Do all my normal queries on the above database on the local PC/Server in stead of doing multiple queries to the trading server.

4. After 3 - then place the necessary trades, Stop losses etc.

5. Delete the database.... and start over at 1....


When browsing through the forums, all I see are loops, doing multiple single queries..... e.g.

 for(int pos= PositionsTotal(); pos>=0; pos--)

 .......

When speed and lag is important, the above method is highly inefficient.

Any help and sample code is greatly appreciated.

Thanks.

Your "solution" is more laggy.

Reason is:

To fill the database, you need to loop through the data from terminal.

Then you store it in the database.

Now you access the data in the database.

Not even mentioning the overhead of the creation of the database, you do much more work than just looping through.

To remove the database, you could use a red-black tree from the STDLIB. But that would only make sense, if you need to access the data multiple times in a complex way to get an advantage.

Also, you should keep the data around, and not recreate it on every tick. Then perform delta updates to your local storage.

Your whole approach is for sure much slower than just using the terminal functions directly. There would be some special reason required why this approach is required for you, and probably shows a totally different problem with your code design.

If you are having issues with the speed of your code, you will be required to share it here, so we can give some suggestions on how to improve it.
 

Hi Dominique,

I am not sure you are correct.
When looking at the following link......


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


They read 2737 transactions in 48.5ms.

Hence, creating the database and populating it with one query is much faster than multiple single queries.

So I am not sure you are correct in your assumption - except if I am interpreting the data wrong in the above example.

The main purpose is to do one query which gives all the data.. and then to do the individual queries on the local database with no lagtime.

Please advise.

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

Hi Dominique,

I am not sure you are correct.
When looking at the following link......

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

They read 2737 transactions in 48.5ms.

Hence, creating the database and populating it with one query is much faster than multiple single queries.

So I am not sure you are correct in your assumption - except if I am interpreting the data wrong in the above example.

The main purpose is to do one query which gives all the data.. and then to do the individual queries on the local database with no lagtime.

Please advise.


No, the database "idea" is much too slow. Instead focus on making your code more efficient in terms of when and how you query the trade data.

There is no need to query or loop over the trade data on every single tick. You need to be selective about it.

However, we cannot provide a generalised solution, because it depends on your strategy and other factors.

If you need help with your code, then show your code.

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
 
StarBuck99:

I need some help from an experienced developer.

I would like to do the following:

1. Create a database in memory in "OnTick".

2. Do one query from defined StartTime to Timecurrent() and copy all the transactions to above database.

    Benefit is much less interaction with main server, less lag and much less slippage.

3. Do all my normal queries on the above database on the local PC/Server in stead of doing multiple queries to the trading server.

4. After 3 - then place the necessary trades, Stop losses etc.

5. Delete the database.... and start over at 1....


When browsing through the forums, all I see are loops, doing multiple single queries..... e.g.

 for(int pos= PositionsTotal(); pos>=0; pos--)

 .......

When speed and lag is important, the above method is highly inefficient.

Any help and sample code is greatly appreciated.

Thanks.

What are you talking about ?

PositionsTotal() is a local, it has nothing to do with the trading server.

Reason: