Thanks for the article - it was interesting!
Such a question, how is it possible to get information promptly - on the fact of opening/changing a position/order on any symbol?
The need to create a database of current and virtual positions - it is necessary for netting when many Expert Advisors work on one symbol.
Or is it better to embed the code in each EA?
The need to create a database of current and virtual positions is necessary for netting when many Expert Advisors work on one symbol.
Or is it better to embed the code in each EA?
Alexey, it will not work. After all, the service is like a script, with the only difference that it is launched simultaneously with the terminal launch....
Started the terminal, the service jumped out, worked and went to the bottom....
Of course, you can run it in an infinite loop, but how effective it will be, you should decide for yourself....
Alexey, it won't work. After all, the service is like a script, with the only difference that it is launched simultaneously with terminal launch....
Started the terminal, the service jumped out, worked and went to the bottom....
Of course, you can run it in an infinite loop, but how effective it will be, you should decide for yourself....
On the one hand, OnTrade() is missing, on the other hand, if the service will simply summarise orders and write to the database the allowed operations, it may work. But again, the issue of synchronisation is relevant. For strategies that are not critical to the delay and work on the bar opening, it seems realistic to do so. Is it possible to trade through the service? I don't see any restrictions. Then it is possible to receive orders from experts, aggregate them and trade independently with a specified frequency.
The need to create a database of current and virtual positions is necessary for netting when many Expert Advisors work on one symbol.
Or is it better to embed the code in each EA?
Alexey, thanks for your opinion!
Good question. Here we need to weigh all pros and cons. On the one hand, as my colleague Alexey Viktorov pointed out, the service for such a task should be launched in an infinite loop. But on the other hand, the service works in the background and writes/reads from the database itself. If you add the ability to work with the database to each robot, you need to understand that there may be a synchronisation conflict. Something like a mutex will probably help here.
And EAs can instantly process trading events, while the service cannot....
The need to create a database of current and virtual positions is necessary for netting when many Expert Advisors work on one symbol.
Or is it better to embed the code in each EA?
Each robot takes into account its virtual positions by itself. In principle, it does not even know about real ones. The only problem for MM is with lot definition, but I have a fixed lot set via parameters. The only alternative to a fixed lot is to allocate to each robot some percentage of the deposit.
Alexei, thank you for your opinion!
That's a good question. Here we need to weigh all pros and cons. On the one hand, as my colleague Alexey Viktorov pointed out, the service for such a task should be launched in an infinite loop. But on the other hand, the service works in the background and writes/reads from the database itself. If we add the ability to work with the database to each robot, we need to understand that there may be a synchronisation conflict. Something like a mutex would probably help here.
And EAs can instantly process trading events, while the service cannot....
Doesn't SQLite know how to work with transaction queue? I have not dealt with this issue, but you wrote an article, that's why I ask :)
You can write to each section of the base (a separate table), or even each advisor can create its own base, and the service will check the availability of the base and connect it to work.
Of course, the issue is delays, but on the other hand it is compensated by the saved spread.
In my case, each robot takes its virtual positions into account by itself. In principle, it does not even know about real ones. The only problem for MM is with lot definition, but I have a fixed lot set via parameters. The only alternative to a fixed lot is to allocate to each robot some percentage of the deposit.
I want to be universal, so that I could create baskets of Expert Advisors with different logic. If an Expert Advisor is boiling in its own juice, then yes - it is a bit easier there - I did it myself, but experimentally - without saving data to a file/database.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article MQL5 Cookbook — Services has been published:
The article describes the versatile capabilities of services — MQL5 programs that do not require binding graphs. I will also highlight the differences of services from other MQL5 programs and emphasize the nuances of the developer's work with services. As examples, the reader is offered various tasks covering a wide range of functionality that can be implemented as a service.
Let's imagine that we are faced with the following task. The terminal should feature the charts of the currently traded symbols, i.e. the ones featuring open positions.
The rules for open charts are very simple. If there is an open position for one of the symbols, then open the chart of this symbol. If there is no position, there will be no chart. If there are several positions for one symbol, then only one chart will be opened.
Also, let's add some colors. If the position is in profit, then the background color of the chart will be light blue, and if it is in the red, it will be light pink. Zero profit uses the lavender color.
Author: Denis Kirichenko