close all position

 

can we code bulk orders->close all position

i dont want the for loop, i want to close all positions instantly same as we can do manually by right click->bulk order->close all positions

 
neerajkadel10: can we code bulk orders->close all position. i dont want the for loop, i want to close all positions instantly same as we can do manually by right click->bulk order->close all positions

Currently not possible! You have to use a loop, but you can make use of asynchronous requests to make it quicker.

Another option is to "freeze" the gains with a opposite order and then take your time closing the orders with the "Close By" method (if the broker allows it).

 
Fernando Carreiro #:

Currently not possible! You have to use a loop, but you can make use of asynchronous requests to make it quicker.

Another option is to "freeze" the gains with a opposite order and then take your time closing the orders with the "Close By" method (if the broker allows it).

with freeze the gains are you saying if there is an opposite move to the trade the profits are locked 

 
Amos Tsopotsa #: with freeze the gains are you saying if there is an opposite move to the trade the profits are locked 

Yes! It is the basics of a "hedged" position. What counts is the resulting net position. On a netting account, it would automatically close that position.

Please note that I have already explained this to you before:

Forum on trading, automated trading systems and testing trading strategies

Do you trade or have you ever traded “Boom” and “Crash”?

Fernando Carreiro, 2022.10.03 21:21

On MetaTrader, there is no way to place/open or close multiple trades concurrently. There are only two possible solutions I can think of at the moment for closing multiple trades quickly:

  • By closing them asynchronously, ignoring failed attempts, and repeating the process until they are all closed. This works faster than waiting for each position close to be confirmed synchronously.
  • Issue an order of the total volume in the opposite direction, to quickly "freeze" the gain, and then using multiple "CloseBy" for each position, to close them all (but only if the broker allows "CloseBy").