It is strange that this is not working. However there is another solution here:
PositionGetTicket(PositionsTotal()-1)
Thank you for your response! Let me explain the code I'm using and the situation I'm facing.
I'm trying it with a demo account.
ulong ticket = OrderSendR("XAUUSD", ORDER_TYPE_SELL, 0.01, Bid, 3, 0, 0, "666", 0, 0, clrBlack); Alert(ticket); // Returns 0 ulong lastPositionTicket = PositionGetTicket(PositionsTotal() - 1); Alert("Last position ticket: ", lastPositionTicket);
In this code snippet, I'm attempting to send a sell order using the OrderSendR function, which is a modified version of the OrderSend function to support asynchronous orders. After sending the order, I'm trying to retrieve the ticket of the last opened position in my account using the PositionGetTicket function.
However, I'm encountering an issue where ticket always returns 0 , even when the order executes successfully. I've tried using PositionGetTicket(PositionsTotal() - 0) instead of PositionGetTicket(PositionsTotal() - 1) ,
Returns the ticket opened in MT5 before.
image:
.I'm sorry for my English
I appreciate any help or suggestions to resolve this issue!
I tried using OrderSend instead of OrderSendAsync and it is working. It has something to do with the Asynchronous functionality.
Intenté usar OrderSend en lugar de OrderSendAsync y está funcionando. Tiene algo que ver con la funcionalidad asincrónica.
Thank you for sharing your insights; they have been very helpful to me. It seems that the issue was related to the asynchronous nature of trading operations. After further investigation, I have discovered that the OrderSendAsync function sometimes returns a ticket of 0 immediately after sending an order. To address this issue, I plan to modify my approach and consider using OrderSend, as you have suggested.
Best regards,
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone!
I'm facing an issue with an MQL5 script that executes a buy order but returns the ticket number as 0. I have verified that the order is executed correctly, but when printing the value of ticket , I always get 0.
Here is my code:
I have verified that the order is executed correctly in mt5 and returns a valid ticket for the order. However, when printing the value of ticket , I always get 0.
Does anyone have any idea what could be causing this issue? Is there something I am overlooking in my code or something else I can check?
Any help or suggestions would be greatly appreciated! Thank you very much in advance.