how to close all orders in build 600?

 

Hello,

My old ea is not worked when i update to  build 600. 

This is how i write. it only can close the last order.

could you tell me what's the problem?

thanks. 

----------------------------------------------------------------------------------- 

void closeall()

  {

   int total=OrdersTotal();

   Print("Close ALLLLLLLLLLLLLLLLLLLL");

   for(int i=total-1;i>=0;i--)

     {

      if(!OrderSelect(i,SELECT_BY_POS)) continue;

        {

         if(OrderMagicNumber()==magicnum)

           {

            if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,White))

               Print("OrderClose error ",GetLastError());

            return;

           }

        }

     }

  }

 

It didn't work before build 600 either.

----------------------------------------------------------------------------------- 

void closeall()

  {

   int total=OrdersTotal();

   Print("Close ALLLLLLLLLLLLLLLLLLLL");

   for(int i=total-1;i>=0;i--)

     {

      if(!OrderSelect(i,SELECT_BY_POS)) continue;

        {

         if(OrderMagicNumber()==magicnum)

           {

            if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,White))

               Print("OrderClose error ",GetLastError());

            return;

           }

        }

     }

  }

 The return means that the loop is stopped after the first run

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. My old ea is not worked
    "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. There isn't anything wrong with that code. Ignoring occasional error if market is close to any TP/SL set. MarketInfo(_Symbol, MODE_STOPLEVEL) * Point
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. My old ea is not worked
    "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. There isn't anything wrong with that code. Ignoring occasional error if market is close to any TP/SL set. MarketInfo(_Symbol, MODE_STOPLEVEL) * Point

Sorry for my bad english...

i just don't know how to write a close all orders function,

could you teach me? thanks 

 
GumRai:

It didn't work before build 600 either.

 The return means that the loop is stopped after the first run

Sorry for my bad english...

i just don't know how to write a close all orders function,

could you teach me? thanks 

 
void closeall(){
   Print("Close ALLLLLLLLLLLLLLLLLLLL");
   for(int total=OrdersTotal(); total > 0;){ --total;
      if(OrderSelect(total,SELECT_BY_POS)
      && OrderMagicNumber()==magicnum){
         if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,White))
               Print("OrderClose error ",GetLastError());
     }
  }
 
lihujie18:

Sorry for my bad english...

i just don't know how to write a close all orders function,

could you teach me? thanks 

Remove the return from your loop
Reason: