Download MetaTrader 5

Delete pendding order after stop loss ?

To add comments, please log in or register
appdroidmega
31
appdroidmega  
Hello everyone, I have this code to delete pending orders after Take Profit .. works fine.

How can I modify to delete orders after Stop Loss?


int LastOrderProfit(int Magic) 
{
  int profit =  0;
  datetime dt = 0;
  
  int cnt = HistoryTotal();
  for (int i=0; i < cnt; i++) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
    
    if (OrderSymbol() != Symbol()) continue;
    if (OrderMagicNumber() != Magic) continue;
        
    if (OrderCloseTime() > dt) {
      dt = OrderCloseTime();
      profit = OrderProfit();
     
    }
    }  
  return (profit);
}

//======================================================================


//-----------------------------
int CountOrders(int Magic)
{
 int count=0;
 int i;
 int total=OrdersTotal();
 for(i=0;i<total;i++)
 {
  OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  
  if(OrderSymbol()!=Symbol() || OrderMagicNumber() != Magic )
   continue;
   
  if(OrderType()>OP_SELL)continue;
  count++;
 }
 return(count);


Mladen Rakic
62953
Mladen Rakic  
appdroidmega:
Hello everyone, I have this code to delete pending orders after Take Profit .. works fine.

How can I modify to delete orders after Stop Loss?



It works for stop loss hit too - not just for take profit filled

Those functions do not make a difference if the order(s) was/were closed using stop loss or take profit and none of the code you posted deletes any pending order(s)

To add comments, please log in or register