Help EA - When opening BUYSTOP delete pending SELLSTOP and conversely.

 

I need help with setting up a waiting instruction. When system opening OP_BUYSTOP => OP_BUY, i need delete pending order OP_SELLSTOP. How?

int start()
  {
//---
   int Den = DayOfWeek(); // zjistí den v týdnu (neděle=0 … pátek=5)
   int Hodina = TimeHour(TimeCurrent()); // zjistí aktuální hodinu
   int Minuta = TimeMinute(TimeCurrent()); // zjistí aktuální minutu
      
   
   double MotherCandelHigh = iHigh(Symbol(), PERIOD_CURRENT, 3);
   double MotherCandelLow = iLow(Symbol(), PERIOD_CURRENT, 3);
   double InsideCandelHigh = iHigh(Symbol(), PERIOD_CURRENT, 2);
   double InsideCandelLow = iLow(Symbol(), PERIOD_CURRENT, 2);
   double OutsideCandelHigh = iHigh(Symbol(), PERIOD_CURRENT, 1);
   double OutsideCandelLow = iLow(Symbol(), PERIOD_CURRENT, 1);
   
   
   double SL = StopLoss * Point;
   double PT = ProfitTarget * Point;
   double POS = Posun * Point;
   int EXP = Expirace * 3600;
   double Spread = MarketInfo(Symbol(),MODE_SPREAD) * Point;
           
   int MagicNumber = 1001;
   int ticket, q;

   for(q = 0; q < OrdersTotal(); q++)
      {if(OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()==MagicNumber)
      {return(0);}}
      
   ///////////////////////
   //// BUYSTOP
   ///////////////////////
   if(Minuta==0 && Den!=0 && MotherCandelHigh>InsideCandelHigh && MotherCandelLow<InsideCandelLow && (OutsideCandelHigh>MotherCandelHigh || OutsideCandelLow<MotherCandelLow))
      {
      ticket = OrderSend(Symbol(),OP_BUYSTOP,Loty,OutsideCandelHigh+Spread+POS,Skluz,MotherCandelLow-SL,OutsideCandelHigh+Spread+POS+PT,"AOS - BUY", MagicNumber,TimeCurrent()+EXP,Blue);        
      } 
   ///////////////////////
   
   ///////////////////////
   //// SELLSTOP
   ///////////////////////
   if(Minuta==0 && Den!=0 && MotherCandelHigh>InsideCandelHigh && MotherCandelLow<InsideCandelLow && (OutsideCandelHigh>MotherCandelHigh || OutsideCandelLow<MotherCandelLow))
   {
   ticket = OrderSend(Symbol(),OP_SELLSTOP,Loty,OutsideCandelLow-POS,Skluz,MotherCandelHigh+SL,OutsideCandelLow-POS-PT,"AOS - SELL", MagicNumber,TimeCurrent()+EXP,Red);
   }
   ///////////////////////
 
   return(0);
  }
 
What have you tried ?
 
Make a loop to walk through orderstotal() if you found a new order with magicnumber that belongs to your buy/sell stop orders.  Then its a new trade.  then make another loop and deletes all opposite pending trades