When I try to close the same position using the below code, another SELL trade gets opened. Why?
MqlTradeRequest closeRequest;
MqlTradeResult closeResult;
ZeroMemory(closeRequest);
ZeroMemory(closeResult);
closeRequest.action = TRADE_ACTION_DEAL;
closeRequest.position = tradeTicket; // Reference the open position
closeRequest.symbol = _Symbol;
closeRequest.volume = lotSize; // Same volume as the open order
closeRequest.type = ORDER_TYPE_SELL; // Close the buy position with a sell order
closeRequest.type_filling = ORDER_FILLING_IOC;
closeRequest.deviation = slippage;
// Send the close requestOrderSend(closeRequest, closeResult);
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I have omitted error handling for brevity. Let's assume there are no error while opening a position. The below code works fine for me.
When I try to close the same position using the below code, another SELL trade gets opened. Why?
if this is not the correct wat, then what is it?