use for loop and scan all tickets
If the ticket cannot be selected then i think the for loop doesn't solve the problem. Because even if you find the ticket, the PositionSelectByTicket will still return false as the original version.
The ticket exist because the order was completely successfully but the PositionSelectByTicket fail to recognise that ticket.
I would like to know if someone experience that situation.
Thank you!
EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.
Hi,
I would like to ask if OrderSend cound return ticket of an order which has not completely.
Here is an example of code :
i observe that sometimes on real account(server) while the ticket is returned the PositionSelectByTicket couldn't be able to select that order.
Is that situation is possible or something i am missing?
Thanks in advance!
asd
1. All is possible as we have no idea what is returned by your Buy() function (are you sure it's a valid ticket ?).
2. The problem is most likely the terminal positions information are not updated yet.
3. Why do you want to modify a position you just open ?
1. All is possible as we have no idea what is returned by your Buy() function (are you sure it's a valid ticket ?).
2. The problem is most likely the terminal positions information are not updated yet.
3. Why do you want to modify a position you just open ?
Thank you for the reply!
1) I am sure that is valid ticket because when the PositionSelectByTicket function fails firstly it prints that failed and secondly prints which ticket tried to select. So the ticket number which is printed ,is the same with the ticket number of the open order which opened at the same time with the message.
2) I will read it!
3)Some types of accounts(ECN BROKERS) doesn't allow to set the stoploss and takeprofit together with the OrderSend. So in these situations we need to set these properties after the order is completely. Correct me if i am wrong.
Yes it is correct on ECN you first open the position without TP and SL and then select the position to assign these values.
In your case:
To make sure that you receive valid position data, it is recommended to call PositionSelect() before you access the data.
https://www.mql5.com/en/docs/trading/positionselectbyticket
Did you print GetLastError() ? what code did it give ?
- www.mql5.com
md42:
...
3)Some types of accounts(ECN BROKERS) doesn't allow to set the stoploss and takeprofit together with the OrderSend. So in these situations we need to set these properties after the order is completely. Correct me if i am wrong.
That's not exact. You can set your sl/tp at the same time even with an ECN broker.
Yes it is correct on ECN you first open the position without TP and SL and then select the position to assign these values.
In your case:
To make sure that you receive valid position data, it is recommended to call PositionSelect() before you access the data.
i observe that sometimes on real account(server) while the ticket is returned the PositionSelectByTicket couldn't be able to select that order.
Is that situation is possible or something i am missing?
When sending a market order (MqlTradeRequest.action=TRADE_ACTION_DEAL), the successful result of the OrderSend() function does not mean that the order has been executed (appropriate trades have been performed). In this case, 'true' means only that the order has been successfully placed in the trading system for further execution. The trade server can fill in the deal or order field values in the returned result structure, if it is aware of these data when forming a response to an OrderSend() call. Generally, event(s) of executing trades corresponding to an order may happen after sending a response to the OrderSend() call. Therefore, for any type of a trade request, when receiving the OrderSend() execution result, we should first check the retcode trade server response code and theretcode_external external system response code (if necessary) available in the obtained result structure.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I would like to ask if OrderSend cound return ticket of an order which has not completely.
Here is an example of code :
i observe that sometimes on real account(server) while the ticket is returned the PositionSelectByTicket couldn't be able to select that order.
Is that situation is possible or something i am missing?
Thanks in advance!
asd