apply close all script on all open charts

 

Hi all,

i used the following script to close all open orders.

extern bool CloseAll = false;

int start()
{
int i=0;
if(CloseAll==true) 
 {
  for(i=0;i<OrdersTotal();i++)
   {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()==OP_BUY)
     {
      OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
      continue;
     }
    if(OrderType()==OP_SELL)
     {
      OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
      continue;
     }
    if(OrderType()==OP_BUYSTOP||OP_BUYLIMIT||OP_SELLSTOP||OP_SELLLIMIT)
     {
      OrderDelete(OrderTicket());
      continue;
     }
   }
 }
return(0);
}

but i would love to apply this on all charts at once

i tried modifying other scripts but couldn't get it to work.

anybody got a clever idea?

 
  1. if(OrderType()==OP_BUYSTOP||OP_BUYLIMIT||OP_SELLSTOP||OP_SELLLIMIT)
    
    if this even compiles, it's equivalent to OrderType()=OP_BUYSTOP or true or true or true
  2. for(i=0;i<OrdersTotal();i++)
       {
        OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    
    
    You must count down in the presence of multiple orders (multiple charts.) Always test return codes. Must RefreshRates() between multiple server calls
    for(pos=OrdersTotal()-1; pos >= 0; pos--) if(
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
        if (OrderType() <= OP_SELL)
          OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Red);
        else
          OrderDelete(OrderTicket());
        RefreshRates();
    
    }
    

 

Thanks for your great response. Tried several things, but not one of them worked.

i first got errors that magic.number not exist and that pos is not a variable or something. so i needed some tweaks but never got this to work.

could u add a full completed script. thanks for the great help!