Unable to close order

i am doing 1 buy stop and 1 sell stop order every 10am daily. and close both the next day whether open or pending. but when run run backtest, the pending one not opened cant close b4 the next 10pm. if there something wrong with my closing order code?

if (Hour()== StartHour)
{

if(FirstTick == true)
{
FirstTick = false;

  Alert("Acc Bal is ", AccountBalance());
  double HighestHigh=-1, LowestLow =999;
  
  //check for highest high and lowest low
  for(int i = 1; i<=NoOfBars; i++)
  {
     if(High[i] > HighestHigh)
     HighestHigh = High[i];
           
     if(Low[i] < LowestLow)
     LowestLow = Low[i];
  } 
       
  Alert("u r using ", TimeChart, " chart, checking for ", NoOfBars, " bars");
  Alert("Highest high for the last ", NoOfBars," bars is ", HighestHigh);
  Alert("lowest low for the last ", NoOfBars," bars is ", LowestLow);
     
     
  //check for any opening order. if yes, close
  int TotalOrders = OrdersTotal();
  for(int j=TotalOrders-1; j>=0; j--)
  {
     bool OpenOrder = OrderSelect(j, SELECT_BY_POS);   //select by order pool (open and pending order only)
    
     int Type = OrderType();
     bool CloseResult = false;
        
     if(Type == OP_BUYLIMIT == OP_SELLLIMIT == OP_BUYSTOP == OP_SELLSTOP) CloseResult = OrderDelete(OrderTicket());
     if(Type == OP_BUY) CloseResult = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 100, Red );
     if(Type == OP_SELL) CloseResult = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 100, Red );
        
     if(CloseResult==false) Alert("Order " , OrderTicket() , " failed to close. Error: " , GetLastError() );
     if(CloseResult==true) Alert("Order " , OrderTicket() , " successfully closed! ");
     
 }
  
 int ticket1 = OrderSend(Symbol(), OP_BUYSTOP, Lots, HighestHigh + 10 * Point * 10, 100, LowestLow, HighestHigh + TakeProfit * Point * 10, "Buy Stop"); 
 int ticket2 = OrderSend(Symbol(), OP_SELLSTOP, Lots, LowestLow - 10 * Point * 10, 100, HighestHigh, LowestLow - TakeProfit * Point * 10, "Sell Stop"); 
 
  if(ticket1 < 0 && ticket2 < 0) 
  {
     Alert("Error sending sell stop order ticket # ", ticket1);
     Sleep(3000);
  }
  }

here is my journal entry

If you refer to error codes appendix, error 0 says “no error return”, I dont know what should that means but for your little troule up there I use the following code:

void closeAllOrders()
{
  for(int i=OrdersTotal()-1; i>=0; i--)
  {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {       
      int orderType=OrderType();  
      int orderTicket=OrderTickt();      
      double orderLots=OrderLots();      
      double orderOpenPrice=OrderOpenPrice();
  
      if(orderType==OP_BUYSTOP || orderType==OP_BUYLIMIT || orderType==OP_SELLSTOP || orderType==OP_SELLLIMIT)
      {
        if(OrderDelete(orderTicket, Red))
        continue;
      }
      if(orderType==OP_BUY)
      {
        if(OrderClose(orderTicket, orderLots, Bid, Slippage, Red))
        continue;
      }
      if(orderType==OP_SELL)
      {
        if(OrderClose(orderTicket, orderLots, Ask, Slippage, Red))
        continue;
      }
    }
  }
}

int openPendingOrders()
{
  if(OrdersTotal()==0)
  {
    if(OrderSend(Symbol(), OP_BUYSTOP, Lots, HighestHigh + 10 * Point * 10, 100, LowestLow, HighestHigh + TakeProfit * Point * 10, "Buy Stop"))
    {
      if(OrderSend(Symbol(), OP_SELLSTOP, Lots, LowestLow - 10 * Point * 10, 100, HighestHigh, LowestLow - TakeProfit * Point * 10, "Sell Stop"))
      return true;
    }
  }
  return true;
}

So call closeAllOrders() and it will close all the orders and then call openPendingOrders() and it will open pending orders but when?
that is up to you!!
I hope that could help.