Download MetaTrader 5

how to close all orders in build 600?

To add comments, please log in or register
Use the Pocket to paste your content. It is convenient!
lihujie18
12
lihujie18 2015.07.05 08: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;

           }

        }

     }

  }

Keith Watford
Moderator
9650
Keith Watford 2015.07.05 11: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

whroeder1
14532
whroeder1 2015.07.05 11: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
lihujie18
12
lihujie18 2015.07.05 13: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 

lihujie18
12
lihujie18 2015.07.05 13: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 

whroeder1
14532
whroeder1 2015.07.05 17: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());
     }
  }
Keith Watford
Moderator
9650
Keith Watford 2015.07.05 19: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
To add comments, please log in or register