Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1850

 

Guys, the problem here is normal...I had to deal with this

When processing on the server requotes and as a result there are no orders to close and there is no request to close again either, as there is no longer a condition to close at profit.

 
Tretyakov Rostyslav requotes on the server and as a result there are no closed orders and there is no new request to close them, because the conditions for closing at profit are already gone.

All my robots close according to the following principle: there is a signal to close, we gather all positions into an array and then it closes them in the loop until there is no "0" left.

It works flawlessly.

 
Vitaly Muzichenko #:

All my robots close according to the following principle: there is a signal to close, we collect all positions into an array, then it closes in a loop until there is "0" left

It works flawlessly.

We can do it this way too, but it seems to me to be easier through a flag, while the result is the same "it closes until there is no "0" left".

Although someone likes it that way, so wiggle))))

 
Vitaly Muzichenko #:

All my robots close according to the following principle: there is a signal to close, we collect all positions into an array, then it closes in a loop until there is "0" left

Works flawlessly.

Same thing. Signal to close = virtual limit which will be handled first in OnTick.

Otherwise requotes will be annoying. The more accurate the signal, the more "twitchy" the prices are.

 
Vitaly Muzichenko #:

All my robots close according to the following principle: there is a signal to close, we collect all positions into an array, then it closes in a loop until there is "0" left

Works flawlessly.

And some people say that one and the same position should not be closed by sending a closing request several times. Otherwise "the broker will banish". This is the first time I've heard that, frankly. Of course, if you make something like DDoS attack from OrderClose function... But it wouldn't work either, because all requests are first sent to the queue. And only then the terminal calmly sends them to server one by one at correct interval. Nevertheless, I wondered whether a ban is possible as a result of frequent OrderClose calls. But so far everyone only confirms that it is not. Except for Andrei of course.

 
It does happen that a position fails to close once, even if it is closed manually (due to network failure, bad connection, requotes, etc.). And the user takes it and tries to close it again. Therefore, the robot should perform similar actions and not be "afraid" of being banned by the broker. That's right.
 

In general, the correct way to close the grid is to collect positions in an array, sort them by lots, and then close them from a larger lot to a smaller one.

This only applies to real trading, in the Strategy Tester you don't have to do it. You can also use limiters, but the code is more complicated in this case.

 
Vitaly Muzichenko #:

In general, the correct way to close the grid is to collect positions in an array, sort them by lots, and then close them from a larger lot to a smaller one.

Well, this only applies to trading on the real account, for trading in the tester you don't have to do that either.

It depends on what lot with what profit. I think it's better to sort positions by profit. And first to close the most "fat"!

 
Mihail Matkovskij #:

It depends on what lot with what profit... I think it's better to sort positions by profit. And close the fattest ones first!

No, the price change of 5 pips in a small lot will not affect you much, but even 1 pip in a large lot will make itself felt. That's why we should cover with a bigger lot

 
If there are both long and short in the grid, then sort by lots of profit, then close long-short-short-short alternately, for nice statistics...
Reason: