Close all symbol function

 

I couldn't figure out what's wrong with my code, i've tried everything i could think of. The buy and sell position is working but the order limit,stop,and stop limit part isn't working.

  void OnTick()
  {
//---
Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

   if  (  OrdersTotal()<3 && PositionsTotal() == 0)  // &&  PositionsTotal()<10 ) //&& result == false) 
   {
   trade.BuyStop(0.10,Ask+100*_Point,_Symbol,0,Bid+2000*_Point,ORDER_TIME_GTC,0,0);
   
   }
  
   if (  OrdersTotal()==3 ) 
   {
   Comment("\n use close positions on friday is activated");
   CloseThisSymbolAll();
   }
   else{
   Comment(" use close positions on friday is not activated");
   Comment ("time is ",(StringSubstr(hoursAndMinutes,0,5)));
   }
  }

void CloseThisSymbolAll()
  {
   int positions,orders;
   ulong inpMagic = 0;
   ulong ticket = PositionGetInteger(POSITION_TICKET);
   int orderType = (int)PositionGetInteger(POSITION_TYPE) ;
   int orderPendingType = (int)OrderGetInteger(ORDER_TYPE);
   string orderSymbol = PositionGetString(POSITION_SYMBOL);
   string orderPendingSymbol = OrderGetString(ORDER_SYMBOL);
   ulong orderPendingTicket = OrderGetInteger(ORDER_TICKET);
   ulong orderMagicNumber = PositionGetInteger(POSITION_MAGIC);
   ulong orderPendingMagicNumber = OrderGetInteger(ORDER_MAGIC);

   for(orders=OrdersTotal()-1, positions=PositionsTotal()-1; positions>=0 || orders>=0;positions--,orders--)
     {
      ulong numTicket = PositionGetTicket(positions);
      ulong numOrderTicket = OrderGetTicket(orders);
      
      if(orderSymbol!=Symbol() || orderMagicNumber!= inpMagic ) continue;
      //if(orderPendingSymbol!= Symbol() || orderPendingMagicNumber!= inpMagic) continue;
         if(orderType==POSITION_TYPE_BUY)
            {
            trade.PositionClose(numTicket);
            }
         else if(orderType==POSITION_TYPE_SELL)
            {
            trade.PositionClose(numTicket);
            }
         else if(orderPendingType==ORDER_TYPE_BUY_LIMIT || orderPendingType==ORDER_TYPE_SELL_LIMIT ||
         orderPendingType==ORDER_TYPE_BUY_STOP||orderPendingType==ORDER_TYPE_SELL_STOP
         ||orderPendingType==ORDER_TYPE_BUY_STOP_LIMIT||orderPendingType==ORDER_TYPE_SELL_STOP_LIMIT)
            {
            trade.OrderDelete(numOrderTicket);
            }
        }
     }
 
Renz Carillo:

I couldn't figure out what's wrong with my code, i've tried everything i could think of. The buy and sell position is working but the order limit,stop,and stop limit part isn't working.

I figured it out the loop is getting stopped when it could not select the position symbol or position magic number, since it is an order and not a position therefore orderSymbol!=Symbol() would always be true,so what i did is just remove the code below:

  if(orderSymbol!=Symbol() || orderMagicNumber!= inpMagic ) continue;
  //if(orderPendingSymbol!= Symbol() || orderPendingMagicNumber!= inpMagic) continue;