help me please , I want close all the oder by one click anyboby can help ? me thank !

 
help me please , I want close all the oder by one click anyboby can help me thank
 please write code for me thank very much !
 
I made a script (or modified one, forget which) to do that:

int start()
{
bool result;
double price;
int cmd,error;
int hedgetotal,hedgecnt;
hedgetotal=OrdersTotal();
for(hedgecnt=0;hedgecnt<hedgetotal;hedgecnt++)
{
if(OrderSelect(hedgecnt,SELECT_BY_POS,MODE_TRADES))
{
cmd=OrderType();
if(cmd==OP_BUY || cmd==OP_SELL)
{
while(true)
{
if(cmd==OP_BUY) price=Bid;
else price=Ask;
result=OrderClose(OrderTicket(), OrderLots(), price, 3, CLR_NONE);
if(result!=TRUE) { error=GetLastError(); Print("LastError = ", error); }
else error=0;
if(error==135) RefreshRates();
else break;
}
}
}
else Print( "Error when order select ", GetLastError());
}
//----
return(0);
  }
 
for(hedgecnt=0;hedgecnt<hedgetotal;hedgecnt++)
and
for(hedgecnt=hedgetotal-1;hedgecnt>0;hedgecnt--)

are different!!!!!!!!!!!!!!!!!
 
I think I saw this problem at another topic, that closing order number 1 makes all remaining orders be renumbered anew from 1. So you'd need to close the higher-numbered positions first, and use a decrementing counter.
 
//---------------------------------------------------------------------
// Close all the market orders
//---------------------------------------------------------------------
 
#property copyright "© RickD 2006-2007"
#property link      "www.e2e-fx.net"
 
int Slippage = 3;
 
void CloseOrders() 
{
  int cnt = OrdersTotal();
  for (int i=cnt-1; i >= 0; i--) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    
    //if (OrderSymbol() != Symbol()) continue;
    //if (OrderMagicNumber() != Magic) continue;
    
    if (OrderType() == OP_BUY) {
      OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage);
    }
    
    if (OrderType() == OP_SELL) {
      OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage);
    }
  }
}
 
void start()
{
     for(int i=0;i<OrdersTotal();i++)
     {               
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
          {
               if(Symbol()==OrderSymbol())
               {
                    if(OrderClose(OrderTicket(), OrderLots(), OrderClosePrice() ,0, Red))
                    {
                         Print("Order " + OrderTicket() + " closed!");                   
                    }
                    else
                    {
                         Print("Error closing order " + OrderTicket());                   
                    }
               }
          }
     }     
}
 
There is no need to Print("Order " + OrderTicket() + " closed/failed!"); MT4 log will contain information about all the operation by default.
 
.. and if you do want to process the order list by ascending index, then a statement like "i -= 1;" is needed upon successful closing, because the successful closing changes the tail of the list from the index of the closed trade, which is removed, and upwards.