Close all orders for Symbol - page 2

To add comments, please log in or register
Mehmet Bastem
794
Mehmet Bastem  
Radonee:
This will not fix the problem , the problem is if i have many orders for example 20 orders and the condition is if the profit of all orders >=100  close and delete all , when the EA start close orders the profit be < 100 then the EA stop closing the orders, i want its still in colse and delete all function till close all 20 orders and after close all orders get out the function.
#property show_inputs
extern double Profit=100;
int start()
{
  if (AccountProfit()>=Profit && Profit>0) CloseAll();
  
  
  return(0);
}

int CloseAll()
{
  int total = OrdersTotal();
  for(int i=total-1;i>=0;i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    int type   = OrderType();

    bool result = false;
    //if(OrderSymbol()==Symbol() && OrderProfit()>=Profit)
    {
    switch(type)
    {
      //Close opened long positions
      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE );
                          break;
      
      //Close opened short positions
      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE );
                          break;

      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
    }
   }
    
  }
  
  return(0);
}



Radonee
23
Radonee  
Keith Watford:

That is precisely what the code above your post does.

yes its precisely if i have opening orders for one symbol but if i have opening orders for more than symbols after it close all orders for one symbols the EA stop working and return for this symbol till close all others symbols orders and Orders Total==0 then it back to working again because the code depending on while(OrdersTotals==0) so it still inside CloseAll function till OrdersTotal become 0.

12
To add comments, please log in or register