Problem about using Array[MT5]

 
void orderfunction::coverbuyspecific_order(string symbol_name,ENUM_POSITION_TYPE positiontype,string comment, int magic)
  {
   int pt = PositionsTotal();
   for(int i = pt - 1; i >= 0; i--)
  // for(int i = 0; i <= pt; i++)
     {
     ulong Pticket=PositionGetTicket(i);
      if(Pticket > 0)
        {
         if(PositionGetString(POSITION_SYMBOL) == symbol_name && PositionGetInteger(POSITION_TYPE) == positiontype && PositionGetString(POSITION_COMMENT) == comment)
           {
            if(magic == 0)
              {
               MqlTradeRequest request = {};
               MqlTradeResult  result = {};
               request.action   = TRADE_ACTION_DEAL; 
               request.type     = ORDER_TYPE_SELL;
               request.symbol   = symbol_name;
               request.volume   = PositionGetDouble(POSITION_VOLUME);
               request.price    = SymbolInfoDouble(symbol_name, SYMBOL_BID);
               request.type_filling =ORDER_FILLING_IOC ;// ORDER_FILLING_FOK;//ORDER_FILLING_IOC
               request.deviation = 100;
               request.position = PositionGetTicket(i);
               request.comment    =comment;  
               request.magic    =magic;  
               if(!OrderSend(request, result))
                  PrintFormat("OrderSend error %d", GetLastError());
              }
            else
              {
               if(PositionGetInteger(POSITION_MAGIC) == magic)
                 {
                  MqlTradeRequest request = {};
                  MqlTradeResult  result = {};
                  request.action   = TRADE_ACTION_DEAL;
                  request.type     = ORDER_TYPE_SELL;
                  request.symbol   = symbol_name;
                  request.volume   = PositionGetDouble(POSITION_VOLUME);
                  request.price    = SymbolInfoDouble(symbol_name, SYMBOL_BID);
                  request.deviation = 100;
                  request.type_filling =ORDER_FILLING_IOC ;// ORDER_FILLING_FOK;//ORDER_FILLING_IOC
                  request.position = PositionGetTicket(i);
                  request.comment    =comment;  
                  request.magic    =magic;  
                  if(!OrderSend(request, result))
                     PrintFormat("OrderSend error %d", GetLastError());
                 }
              }

           }
        }
     }
  }

if(OrderStatus==1)
        {
         ReSetProfitBalance();
         OrderGroupA();         
         MaxNum=ArrayMaximum(BuyOrderPrice,0,WHOLE_ARRAY);
         int MinNum=ArraySize(BuyOrderPrice);
         
         if((TP_A - xbid) < 100*_Point) 
         {
          xF.coverbuyspecific_order(Symbol(),POSITION_TYPE_BUY,"Buy_A"+string(MaxNum)+1,MaxNum);
          xF.coverbuyspecific_order(Symbol(),POSITION_TYPE_BUY,"Buy_A"+string(MinNum)+1,MinNum);
          ArrayRemove(BuyOrderPrice,0,WHOLE_ARRAY);
         }


Hello,I would like to ask about how to delete Array Info after order closed.

The situtation is when my program close order by using coverbuyspecific_order function and arrayremove immediately, however closed order info still in BuyOrderPrice Array and the array serial changed as like as picture show.

Can anybody help me? thanks a lot!