Invalid Request 10013 trying to close order. Metatrader 5

483 Views Asked by At

I can successfully place order and retrieve the ticket id by result.order, but when i try to close the order always get invalid request 10013 using metatrading 5.

Tried to close the order 2 ways. With the below function CloseTradeOrder AND using CTrade.OrderDelete( result.order ).

Here goes my code:



    void PlaceTradeOrder(double volume, ENUM_ORDER_TYPE orderType, double price, double stopLoss, double takeProfit)
    {
       MqlTradeRequest request={};   //https://www.mql5.com/en/docs/constants/structures/mqltraderequest
       MqlTradeResult  result={};
       
       ZeroMemory(request);
       ZeroMemory(result);
       
       request.action = TRADE_ACTION_DEAL;  // Trading action
       request.symbol = Symbol();           // Symbol to trade
       
       request.volume = volume;             // Trade volume
       request.type   = orderType;          // Order type (ENUM_ORDER_TYPE)
       
       request.price = price;               // Order price
       
       request.sl    = stopLoss;            // Stop Loss level
       request.tp    = takeProfit;          // Take Profit level
       
       if(!OrderSend(request, result))
       {
          Print("OrderSend error ", result.retcode);
       }
       else
       {
          Print("Order placed successfully. Order ticket: ", result.order);
       }
    }//-----------------------------------------------------------------------------------------

    void CloseTradeOrder(ulong orderTicket)
    {
       MqlTradeRequest request={};
       MqlTradeResult  result={};

       ZeroMemory(request);
       ZeroMemory(result);
       
       request.action = TRADE_ACTION_REMOVE;  // Trading action
       request.order = orderTicket;            // Order ticket

       if (!OrderSend(request, result))
       {
          Print("OrderSend error ", result.retcode);
          PrintFormat("OrderSend error %d",GetLastError());  // if unable to send the request, output the error code
       }
       else
       {
          Print("Order closed successfully. Order ticket: ", result.order);
          EventKillTimer();
       }
    }//void CloseTradeOrder(ulong orderTicket)
    //+------------------------------------------------------------------+


Any hint?

0

There are 0 best solutions below