Delete pendding order after stop loss ?

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


 
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)