how to close all orders in build 600?

Back to topics list To post a new topic, please log in or register
avatar
3
lihujie18 2015.07.05 10:19
 

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;

           }

        }

     }

  }

avatar
Moderator
3408
GumRai 2015.07.05 13:28 #
 

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

avatar
12988
WHRoeder 2015.07.05 13:49 #
 
  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

avatar
3
lihujie18 2015.07.05 15:48 #
 
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 

avatar
3
lihujie18 2015.07.05 15:49 #
 
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 

avatar
12988
WHRoeder 2015.07.05 19:06 #
 
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());
     }
  }

avatar
Moderator
3408
GumRai 2015.07.05 21:20 #
 
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
Back to topics list  

To add comments, please log in or register