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

 
Mihail Matkovskij #:

Yes. But the lock opens with the same lot. And two differently directed orders are opened simultaneously. And hedging is when a trade has entered a drawdown, and the trader opens a position with a bigger lot in the same direction (with different directions I got mixed up) implying that the price will reverse to make a profit on a trade with a bigger lot and cover the loss of a trade with a smaller lot or average to 0. If I got something wrong, then correct me.

Hedging is absolutely not lock, or partial lock, but a completely different system.

 
Vitaly Muzichenko #:

Hedging is absolutely not lock, or partial lock, but a completely different system.

But I'm not saying it's losk. I just got confused yesterday (I said: you should open an opposite position instead of a unidirectional position). The time was late. And today I understood where I was wrong.

 
Mihail Matkovskij #:

But I'm not saying it's losk. I just got confused yesterday (I said: you should open an opposite position instead of a unidirectional position). The time was already late. And today I realised where I was wrong.

It makes sense then, it happens :)

 
EVGENII SHELIPOV #:

This may be the case provided the command to open an order is given. So there is a kind of "CLICKING" going on.

We need to create a list of orders, with ticks, to close (as many have already said here). If the robot has detected a signal to exit, the corresponding orders (tickets) should be added to the list to close. The list is passed by a cycle which sends closing requests (OrderClose). Then we need to constantly check if there are any open orders with the tickets which have been added to the list. If one or more tickets are not found, we should delete them from the list. In this way, the function will not send a request to close orders which do not exist.

What to do with new signals and orders, which appeared during the period of the filled list? You can also add them to the list to be closed by an exit signal. That way, they will also be closed in their turn. That is all. Create such a list and close orders by the ticket cyclically. You can do it with an interval of a second or a few seconds per one pass of the cycle. All we have to realize this algorithm, and everything will work.

 
Mihail Matkovskij #:

We need to create a list of orders to close (as many have already said here) with tickets. If the robot detects an exit signal, then add the corresponding orders (tickets) to the closing list. The list is passed by a loop which sends a close request (OrderClose). Then we should constantly check if there are any open orders with the tickets which have been added to the list. If one or more tickets are not found, we should delete them from the list. This way, the function will not send a request to close orders which do not exist.

What to do with new orders, which appeared during the period of the filled list? You can also add them to the close list. That way they will also be closed in their turn. That is all. Create such a list and close the orders on the etiquette cyclically. You can do it with an interval of a second or a few seconds per one pass of the cycle. All we have to realize this algorithm and everything will work.

Will it close each one in turn? When the grid is so long, it will close the right ones.
When the last order closes, it may happen that there are 10 orders to be closed and it will close all of them one by one and it will take an infinite amount of time.

 
Alexander Avksentyev #:

When the grid takes so long, it will close the right ones in turn.
When you close the last one, it may happen that there are 10 orders to be closed, so it closes all of them one by one and it takes an infinite amount of time.

This is not quite the case. All of the orders are closed by the terminal one by one. In the OrderSend cycle, it may trigger many times a second (depending on your hardware). But OrderSend only adds the appropriate commands to the closing queue. Thenterminal sends these commands to server at specified interval or after receiving server's response about previous request, not immediately. So, a large number of orders (positions) are closed much slower than a single order, anyway.

 
Alexander Avksentyev #:

When the grid takes so long, it will close the right ones in turn.
When you close the last one, it may happen that there are 10 orders to be closed and it closes all of them one by one and it takes an infinite amount of time.

This process is a non-stop.

If true, we continue; if false, we process an error; critical error, we exit; non-critical (slippage), we continue.

If dealing is not a complete kitchen, 15-20 EAs close quickly, around 2-3 seconds, otherwise up to 15 seconds. Edit, there were cases up to 2 minutes.

If it is mt5, it closes almost instantly.

 
Vitaly Muzichenko #:

It closes without interruption.

After closing one, check what the OrderClose function returned, if true - continue, if false - handle error, critical error - exit, non-critical (slippage) - continue.

If dealing is not a complete kitchen, 15-20 EAs close quickly, around 2-3 seconds, otherwise up to 15 seconds. Edit, there were cases up to 2 minutes.

If it's mt5, it closes almost instantly.

If there is any error, you still need to send a request to close this order after a certain interval. Because if it stays pending forever, it will already be a bad robot. With such an order (position), it is even possible to lose the deposit, if you hold it for a long time.

 
Mihail Matkovskij #:

If there is any error, you still need to send a request to close that order after a certain interval. If it stays there forever, it will be a bad robot. Due to this order (position), the deposit can even be lost if it is held for a long time.

We need to handle it properly. If it is critical, there is no point in pounding the server.

 
Vitaly Muzichenko #:

It has to be handled properly. If it's critical, there's no point in pounding the server.

Of course there is no point. But after a certain interval, you should try to close this order (position). The reason is this. Firstly, the open position cannot hang there indefinitely. Secondly, the position itself cannot be closed forever. Sooner or later, the server will accept a request to close the order(to exit the position). And if you do nothing, the result will be as I mentioned above. The deposit may go into severe drawdown or lose its value.

Reason: