Close Sell limit position

 
            if (position == "sell limit" && type == "(open now) OPEN")      // OPEN SELL LIMIT Position **********************************************
            {
                // Perform action for Sell Limit Open
                // Place the order here
                
               // Prepare trade request
               MqlTradeRequest request;
               ZeroMemory(request);
    
               // Set trade parameters
               request.action = TRADE_ACTION_PENDING; // Perform a trade
               request.type = ORDER_TYPE_SELL_LIMIT; // Buy order
               request.symbol = pair; // Trading symbol
               request.volume = lots * leveragex; // Calculate volume in lots
               request.price = price; // Desired price
               request.sl = sl; // Stop loss level
               request.tp = tp; // Take profit level
               request.magic = orderId; // Order identifier
    
               // Send the trade request
               MqlTradeResult result;
               ZeroMemory(result);
    
               if (OrderSend(request, result))
               {
                     Print("Sell limit order placed successfully. Order ID: ", result.order);
               }
               else
               {
                  Print("Failed to place sell limit order. Error code: ", GetLastError());
               }
                
                
                Print("========================== Sell Limit Open ==========================");
            }
            else if (position == "sell limit" && type == "(close now) CLOSE")      // CLOSE SELL LIMIT Position **********************************************
            {
                // Perform action for Sell Limit Close
                // Close the order here
                
                CTrade selllimitclosetrade;
                
                for (int i=0; i < PositionsTotal(); i++)
                {
                
                ulong ticketslc = OrderGetTicket(i);
                
                // make sure position type/symbol/magic is correct
                if
                (
                PositionGetInteger(POSITION_TYPE) == ORDER_TYPE_SELL_LIMIT &&
                PositionGetString(POSITION_SYMBOL) == pair &&
                PositionGetInteger(POSITION_MAGIC) == orderId 
                )
                     {
                       if (selllimitclosetrade.OrderDelete(ticketslc))
                       {
                         Print("Sell Limit Order Successfully CLOSED. Ticket : ", ticketslc);
                       }
                         else
                        {
                         Print("Failed to close Sell Limit position........ Error Code : ", selllimitclosetrade.ResultRetcode()); 
                        }
                      }
                }                
                
                Print("========================== Sell Limit Close ==========================");
            }

Hi All,


this MQL5 code are open sell limit pending order and cancel the sell limit pending order. Unfortunately, it is working for open position sell limit pending order BUT are not working to close the sell limit pending order. im new to MQL5, any help are highly appreciated 

 
PaulfHi All, this MQL5 code are open sell limit pending order and cancel the sell limit pending order. Unfortunately, it is working for open position sell limit pending order BUT are not working to close the sell limit pending order. im new to MQL5, any help are highly appreciated 

Maybe it's just me, but I don't understand anything.

I would understand if you wanted to close a pending sell order after opening a pending buy order, and vice versa.

Note: I have not looked at the code without first understanding what it is intended to do.

 
i just want to know how to close/cancel a buy limit. i can place a buy limit at mt5 but cant close/cancel the buy limit.
Reason: