This my Close All Script
And this Script enables you to set a hot key (ex: Shift+C) to close all the trades.
- You MUST count down when closing multiple orders (or processing orders in the presence of other charts)
- You MUST refreshRates between multiple server calls
- Always check return codes (orderSelect and orderClose)
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderSymbol() == Symbol() // and my pair. && ( OrderMagicNumber()==magico_10 // and my magic number || OrderMagicNumber()==magico_9 || OrderMagicNumber()==magico_4 || OrderMagicNumber()==magico_8 || OrderMagicNumber()==magico_3 || OrderMagicNumber()==magico_7 || OrderMagicNumber()==magico_2 || OrderMagicNumber()==magico_6 || OrderMagicNumber()==magico_1 || OrderMagicNumber()==magico_5 || OrderMagicNumber()==magico_0 ) && ( (OrderType()==OP_BUY && FecharCompra==1) // and in my ||(OrderType()==OP_SELL && FecharVenda ==1) // allowed direction ) ){ RefreshRates(); if (!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red)) Alert("OrderClose(",OrderTicket(),") failed: ",GetLastError(); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
Given a such condition,
how can I close all the BUY, or all the SELL, opened orders at once?
Example:
It must look for all the Buy opened orders, each one matching with a list of different magic numbers, and then, select all of it and close all of them at once. This must be valid to opened Sell orders.
I already tried to use the following module, but it closes only one order each time the price ticks, and I want to close it all at once.
-------------------------------------
int Total1 = OrdersTotal(),
n;
for(n=0;n<Total1;n++)
{
OrderSelect(n,SELECT_BY_POS,MODE_TRADES);
if ( OrderSymbol()==Symbol() //&& OrderComment()==comenta
&& (OrderMagicNumber()==magico_10 || OrderMagicNumber()==magico_9 || OrderMagicNumber()==magico_8 || OrderMagicNumber()==magico_7 || OrderMagicNumber()==magico_6 || OrderMagicNumber()==magico_5 || OrderMagicNumber()==magico_4 || OrderMagicNumber()==magico_3 || OrderMagicNumber()==magico_2 || OrderMagicNumber()==magico_1 || OrderMagicNumber()==magico_0) )
{
if (OrderType()==OP_BUY)
{
if (FecharCompra==1)
{
if ( OrderMagicNumber()==magico_9 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_8 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_7 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_6 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_5 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_4 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_3 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_2 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_1 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_0 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
}
}
if (OrderType()==OP_SELL)
{
if (FecharVenda==1)
{
if ( OrderMagicNumber()==magico_9 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_8 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_7 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_6 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_5 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_4 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_3 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_2 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_1 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
if ( OrderMagicNumber()==magico_0 ) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Red);
}
}
}
}
Regards