PositionsTotal(), PositionSelect()... why is it not working?

 

I have created a small EA which has manage to successfully sends a pair of buy/sell stop orders correctly.  Now, if any of them gets triggered, the other pending order is deleted.

I use the above commands, but they are not working. PositionsTotal() keeps giving me zero, and positionSelect() keeps returning false, even when pending orders are triggered. Whats wrong with my code:

 Print("here - " , PositionsTotal());

//+------------------------------------------------------------------+
uint exit(string ins){
//+------------------------------------------------------------------+
   uint res=0;
  
   if(PositionSelect(ins)){
      Print("here");
      for(int a=OrdersTotal()-1;a>=0;a--){
         ulong tkt=OrderGetTicket(a);
         if(OrderSelect(tkt))
            if(OrderGetInteger(ORDER_TYPE)>1){
               CTrade *pender = new CTrade;
               pender.OrderDelete(tkt);
               res=pender.ResultRetcode();
               Print("EXIT --- ",tkt);
               delete pender;
            }
      }
   }
   return(res);
}
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5