market order #xxx cannot be deleted

 
Hi.

I'm trying to delete an order but I only get:
market order #58321089 cannot be deleted.

I know that the ID is correct. I also know that the order is still live.

Why can this be?


//+------------------------------------------------------------------+
void CanceledOrder(string myType,string mySymbole,string myTradeID,int myPosition,double myEntry,double myStopLoss,double myTakeProfit)
  {
   Print("[CanceledOrder] - commentOnOpenOrders = "+DoubleToStr(commentOnOpenOrders(myTradeID)));
   Print("[CanceledOrder] - commentOnOpenHistory = "+DoubleToStr(commentOnOpenHistory(myTradeID)));
   if(commentOnOpenOrders(myTradeID))
     {
      int PositionIndex;    //  <-- this variable is the index used for the loop
      int TotalNumberOfOrders;   //  <-- this variable will hold the number of orders currently in the Trade pool
      TotalNumberOfOrders = OrdersTotal();    // <-- we store the number of Orders in the variable

      for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  //  <-- for loop to loop through all Orders . .   COUNT DOWN TO ZERO !
        {
         if(! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES))
            continue;   // <-- if the OrderSelect fails advance the loop to the next PositionIndex
         if(OrderComment() == myTradeID)
            if(! OrderDelete(OrderTicket(),clrRed))
               Print("[OrderDelete] - Order OrderModify failed, order number: ", OrderTicket(), " Error: ", GetLastError());
            else
               Print("[OrderDelete] - OrderSend placed successfully");
         deleteFile_Canceled(fileName_Canceled);
        }
     }
   else
     {
      Print("TradeID Already exists = "+myTradeID);
      deleteFile_Canceled(fileName_Canceled);
     }
  }

//+------------------------------------------------------------------+

 
Mathias Halen:
Hi.

I'm trying to delete an order but I only get:
market order #58321089 cannot be deleted.

I know that the ID is correct. I also know that the order is still live.

Why can this be?

You cannot delete a market order.

You don't check in your code whether the order is a pending order or not.

 
Mathias Halen: I'm trying to delete an order but I only get: market order #58321089 cannot be deleted. I know that the ID is correct. I also know that the order is still live. Why can this be?

You Delete Pending Orders and you Close Market Orders and not the other way round.

 
Keith Watford:

You cannot delete a market order.

You don't check in your code whether the order is a pending order or not.

Thank you. I just changed the code so it only delets pending orders and modifys open orders

Reason: