Close all orders for Symbol - page 2

 
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);
}



 
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.

 

Hi

How would we change the code to close only/certain orders that add up to the Profit required? 

 
Mehmet Bastem:

I have been trying to add a close orders function in an EA I am working on. Had a tough time finding one that either worked or that I could fix to make it work. I inserted the close_orders() function you posted and now its all rainbows and unicorns.

I shall study it to see how it works and learn, as my current project is as much a learning endeavor as an actual project.

Thank you for taking the time to post it.