Close all trades at once

 

I was wondering if anyone can help me with a small issue, I have an EA that closes basket of trades once a certain profit is reached. For example this past week there was a basket of 27 open buys/sells that took 7 seconds to close, in the mean time price had moved 2-3 pips and

it ended up as a losing basket. Is there any way that all the open trades can be closed all at one time ?? My programmer does not have a solution, but he did add some code to close the biggest lot size trades first, which helps somewhat but still does not solve the issue. Part of my requirement document clearly stated that "all baskets must be closed at a profit". 

 
George:

I was wondering if anyone can help me with a small issue, I have an EA that closes basket of trades once a certain profit is reached. For example this past week there was a basket of 27 open buys/sells that took 7 seconds to close, in the mean time price had moved 2-3 pips and

it ended up as a losing basket. Is there any way that all the open trades can be closed all at one time ?? My programmer does not have a solution, but he did add some code to close the biggest lot size trades first, which helps somewhat but still does not solve the issue. Part of my requirement document clearly stated that "all baskets must be closed at a profit". 

Do not close at market price. Use TP and SL instead
Get a VPS closer to the broker server so the latency will be reduced

 
Fernando Morales:

Do not close at market price. Use TP and SL instead
Get a VPS closer to the broker server so the latency will be reduced

The demo is already running on a VPS, and there is a basket TP, cant use pending orders if thats what you meant. There has to be a way to close all open trades at once, like as cript of something.

 
Fernando Morales:

Do not close at market price. Use TP and SL instead
Get a VPS closer to the broker server so the latency will be reduced

I agree; closing with SL or TP is much faster than closing each order sequentially

 
George:

The demo is already running on a VPS, and there is a basket TP, cant use pending orders if thats what you meant. There has to be a way to close all open trades at once, like as cript of something.

The TP and SL are pending orders effectively. Use them if you want faster trade closing results. Using a script is the same as closing with an EA. Another option is adding more pìps to the trigger price. If you are using MT5 there is an option for asynchronous Ordersend but this imposes a higher risk of leaving one or more trades opened because the EA does not wait for server confirmation.

If you are having such troubles with a demo account, using a live account will be worse. 

My suggestion is: getting a VPS with latency under 20ms to the broker server and using TP/SL.

 
  1. George: There has to be a way to close all open trades at once,

    There doesn't "has to be a way" at all. You have to close one after one and that can take minutes during news.

  2. George: my requirement document clearly stated that "all baskets must be closed at a profit". 
    Irrevalent; the world doesn't revolve around you.

  3. People, OP is trading a basket of different pairs. There is no SL/TP for a basket; only for individual orders.
 
William Roeder:
  1. There doesn't "has to be a way" at all. You have to close one after one and that can take minutes during news.

  2. Irrevalent; the world doesn't revolve around you.

  3. People, OP is trading a basket of different pairs. There is no SL/TP for a basket; only for individual orders.

Interesting. I dont know much about basket trading. Perhaps a solution is setting TP or SL of all orders at 1pip or STOPLEVEL when profit target is reached

 
Fernando Morales: Perhaps a solution is setting TP or SL of all orders at 1pip or STOPLEVEL when profit target is reached

1) They will not close that the same time, 2) the basket will close at a different profit level than OP wants.

 
William Roeder:

1) They will not close that the same time, 2) the basket will close at a different profit level than OP wants.

Make sense.

An alternative, this comment about creating worker EAs to distribute the closing tasks: https://www.mql5.com/en/forum/345217#comment_17071083 

How to Send Orders Asynchronously With MQL4?
How to Send Orders Asynchronously With MQL4?
  • 2020.06.25
  • www.mql5.com
There is no way to get to the point...
 
Fernando Morales: An alternative, this comment about creating worker EAs to distribute the closing tasks: https://www.mql5.com/en/forum/345217#comment_17071083 

Still no. Used to be only one trade context (146) was enlarged to 8 (Build 600) but OP has 27 open orders. That will quicken but still not make it "at once"

 

Thanks for the feedback guys, first of all its an MT4 and not an MT5 EA. When I say basket profit I mean on one pair, because I dont trade multiple pairs. A previous version of this same logic with another programmer, who BTW could not get the missing trade bug fixed and therefore failed. We had a parameter where you would set it to 1-2 pips, so when the Min Basket Profit was hit price would have to move an additional 1-2 pips more in the same direction of course, and every damn basket closed out in profit after that.

I was assuming that there was some sort of script or piece of code that could close all trades in a few MS, or all at once but you guys are telling me differently.