The script close all open orders

 
These do'nt work anymore on Interbank platform 216 can anyone help?
 
This does not work either help please.
 

Maybe link below will be of use to you.

I found this few years ago - never got around to doing own since it works ok for me so never bothered.

I saved with a name that put at top of scripts list in Terminal's navigator tree, this way if want to start it fast I at least know where to look and/or could assign a hot key to it also...

Name I used was _AAA_CloseAll_ORDERS

not highly original but serves my simple needs...

http://www.xpworx.com/Close%20All.htm

 

Update the link to:

CloseAll

And there's a new script to Close All Trades with A Hot Key press here:

Close All Hot Keys

 

Any feedback is appreciated.

 

I updated the Close All script.



 
codersguru:

Any feedback is appreciated.



Try to close more then two orders a row and you'll see your script is sucks.
 
//+-----------------------------------------------------------------|
//| WARNING: Use At Your Own Risk!                                  |
//|                                                                 |
//| [Script] Close all open orders                                  |
//| Copyright © 2006, Ruby Salton, www.TornadoFX.co.il              |
//+-----------------------------------------------------------------+
#property copyright "Copyright © 2006, Ruby Salton"
#property link      "www.TornadoFX.co.il"

#define SLIPPAGE              5
#define NO_ERROR              1
#define AT_LEAST_ONE_FAILED   2

int start()
{
   while (CloseAll() == AT_LEAST_ONE_FAILED)
   {
      Sleep(1000);
      Alert("Order close failed - retrying error#: ", GetLastError());
   }
}


int CloseAll()
{ 
   bool rv = NO_ERROR;
   int numOfOrders = OrdersTotal();
   int FirstOrderType = 0;
   
   for (int index = 0; index < OrdersTotal(); index++)   
     {
       OrderSelect(index, SELECT_BY_POS, MODE_TRADES);
       if (OrderSymbol() == Symbol()) 
       {
         FirstOrderType = OrderType();
         break;
       }
     }   
         
   for(index = numOfOrders - 1; index >= 0; index--)
   {
      OrderSelect(index, SELECT_BY_POS, MODE_TRADES);
      
      if (OrderSymbol() == Symbol())
      switch (OrderType())
      {
         case OP_BUY: 
            if (!OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), SLIPPAGE, Red))
               rv = AT_LEAST_ONE_FAILED;
            break;

         case OP_SELL:
            if (!OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), SLIPPAGE, Red))
               rv = AT_LEAST_ONE_FAILED;
            break;

         case OP_BUYLIMIT: 
         case OP_SELLLIMIT:
         case OP_BUYSTOP: 
         case OP_SELLSTOP:
            if (!OrderDelete(OrderTicket()))
               rv = AT_LEAST_ONE_FAILED;
            break;
      }
   }

   return(rv);
}
 
Roger:

Try to close more then two orders a row and you'll see your script is sucks.

I just tried to close 5 orders

2011.09.20 21:46:09 CloseAll GBPUSD,H1: delete #67127798 sell stop 0.01 GBPUSD at 1.5678 sl: 0.0000 tp: 0.0000 ok
2011.09.20 21:46:06 CloseAll GBPUSD,H1: close #67127783 buy 0.01 GBPUSD at 1.5727 at price 1.5726
2011.09.20 21:46:03 CloseAll GBPUSD,H1: close #67127764 sell 0.01 GBPUSD at 1.5726 at price 1.5729
2011.09.20 21:46:00 CloseAll GBPUSD,H1: delete #67127700 sell stop 0.01 EURUSD at 1.3650 sl: 0.0000 tp: 0.0000 ok
2011.09.20 21:46:00 CloseAll GBPUSD,H1: delete #67127700 sell stop 0.01 EURUSD at 1.3650 sl: 0.0000 tp: 0.0000 ok

and no SUCKS at all

 

You have wrong place to refresh Bids and Asks, If prices change, it'll never been refresh.

bool CloseOrder(int ticket, double lots, int slippage, int tries, int pause)
{
   bool result=false;
   double ask , bid;
   
   if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
   {
      RefreshRates();//wrong place!!!
      ask = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS));
      bid = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS));
      
      if(OrderType()==OP_BUY)
      {
         for(int c = 0 ; c < tries ; c++)
         {
            if(lots==0) result = OrderClose(OrderTicket(),OrderLots(),bid,slippage,Violet);
            else result = OrderClose(OrderTicket(),lots,bid,slippage,Violet);
            if(result==true) break; 
            else
            {
               Sleep(pause);
               continue;
            }
         }
      }
      if(OrderType()==OP_SELL)
      {
         for(c = 0 ; c < tries ; c++)
         {
            if(lots==0) result = OrderClose(OrderTicket(),OrderLots(),ask,slippage,Violet);
            else result = OrderClose(OrderTicket(),lots,ask,slippage,Violet);
            if(result==true) break; 
            else
            {
               Sleep(pause);
               continue;
            }
         }
      }
   }
   return(result);
}
 
Roger:

You have wrong place to refresh Bids and Asks, If prices change, it'll never been refresh.

Changing the position of RefreshRates makes no difference . . . Bid and Ask aren't used.
Reason: