There are ways to code what you want without new functions. How about keeping track of all the orders in a grid with separate magic numbers?
My idea about grouping orders has nothing to do with magic numbers, but it's a suggestion for MetaTrader company. I m talking about closing, modifying or deleting a group of trades in one second!
Exactly what I was after
Hi Guys,
I logged on today to find an answer to exactly this question.
Is it possible to send multiple orderopen or orderclose messages simulateously??
My EA sometimes has a number of positions open at one time, but I want to close them all together. While it does not take a very long time to close 10-15 positions, it takes too long (maybe 2 secs).
I am using the following code to close orders (which I think is pretty standard)
for(cnt=total-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,4),3,Blue);
}
It appears that the system sends one orderclose, then waits for a confirmation before sending the next orderclose.
I would like to send all the closes together, then get back the conf's after...
Anyone got any ideas???
I am using the following code to close orders (which I think is pretty standard)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,4),3,Blue);
}[/CODE]One thing that's wrong with this code is that it uses Ask as price without distinguishing between buy and sell orders and also that it only considers the current symbol on the chart. So you would need at least something like this:
[CODE]for(cnt=total-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (Ordertype() == OP_BUY)
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(), MODE_BID),3,Blue);
else if (Ordertype() == OP_SELL)
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(), MODE_ASK),3,Red);
}Sorry, back to the purpose of the thread...
Close all open or pending orders:
if (Use your own conditional statement here)
{
while(OrdersTotal()>0)
{
OrderSelect(0,SELECT_BY_POS);
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);
if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());
}
return(0);
}
Quickest way that I know how to do it!
Yeah right, that's better, because it also takes pending orders into account...
Hi Guys,
My EA checks for the position direction outside the close loop to speed things up. You are correct though that it does not work for multi currency.
The suggestions you have posted are all the same as mine in the manner in which they opperate. I am looking for a way to send multiple orderclose messages simultaneously, or somehow queue the messages.
And the reason I posted it on this thread is that the suggestions in the first post would solve this problem. I am simply asking if anyone knows of another way.
Thanks

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, since I am writing GridTrading EA, I should suggest a number of new order functions to group or ungroup a number of trades, to modify grouped trades, to close grouped trades. This should win time in comparison to modify or to close a number of trades separately.
I try to imagine this in MQL code:
// This gives a group ticket number
int OrderCreateGroup();
// This adds an open or pending trade to an exising group
bool OrderGroupAdd( int GroupTicket, int Ticket );
// This removes a grouped trade from the group
bool OrderGroupRemove( int GroupTicket, int Ticket );
// This clears a group
bool OrderClearGroup( int GroupTicket );
// This gives a number of trades in group
int OrderGroupCount( int GroupTicket );
// This modifies a group of trades with a new prices (only pending group), new stoploss or new takeprofit
bool OrderGroupModify( int GroupTicket, double price, double stoploss, double takeprofit );
// This closes a group of trades
bool OrderGroupClose( int GroupTicket, double lots, double price, int slippage );
// This closes a group of pending trades
bool OrderGroupDelete( int GroupTicket );
Any comments about this idea???
Jeff