This forum is now read-only. You can discuss you questions on Forums of MQL4.community and MQL5.community
Determining if an Order SucceededBack to topics list |
|
AndrewSchwartz
2005.05.04 01:06
I am using the MetaTrader API. From what I understand, on a MtSendOrder API call, even if the return value is RET_OK, I am not guaranteed that the order has gone through. Presumably, if/when my order appears on the list from MtGetTradeRecords, I know that my order was successfuly. However, how do I know if the order failed? How long should I wait before giving up?
Basically, I don't see any notification in the API that lets the client know that an order has failed. In my program, if an order fails, I might want to replace the same order with a different price. However, I don't want to be in a situation where I replaced an order, thinking that the first order failed, but I was incorrect and both succeeded, leaving me in a position with twice the position I wanted. Thanks in advance. |
4464 |
Slawa
2005.05.04 10:59
if order fails then MtSendOrder returns error code not RET_OK! and You can analyze returned codes always
please see our samples. for instance:
SendOrderInfo soi;
::ZeroMemory(&soi,sizeof(soi));
strcpy(soi.symbol,"USDCHF");
soi.cmd=OP_BUY;
soi.volume=100;
soi.price=ask;
if((err=api.SendOrder(&soi))!=RET_OK)
{
printf("Error sending order: %s\n",api.GetErrorDescription(err));
return(-1);
}
printf("8. long position opened\n");
|
|
AndrewSchwartz
2005.05.04 11:04
I asked a related question to support@metaquotes.ru. Below is a snippet from the email:
Hello, Andrew Schwartz, **begin snippet** > On the MT3 api, when I call SendOrder and the return value is 0 (success), does that guarantee that the order will go through? No. > Does SendOrder perform an asynchronous call or a synchronous call? I noticed that the trade list is not updated immediately - this is concerning to me. Asynchronous. Best regards, Mazhit Mugattarov, MetaQuotes Software Corp. **end snippet** I'm confused. If I get a RET_OK (return value of 0) as a response to the SendOrder call, then that guarantees that the order will go through? You seem to indicate that it does provide a guarantee, but Mazhit Mugattarov indicates that it does not. Thank you in advance. |
4464 |
Slawa
2005.05.04 11:13
there is misunderstanding, sorry
|
|
AndrewSchwartz
2005.05.04 11:16
then which is correct? Could I get a clarification? If Mazhit is correct, I would like to ask my question again:
"Presumably, if/when my order appears on the list from MtGetTradeRecords, I know that my order was successfuly. However, how do I know if the order failed? How long should I wait before giving up?" |
4464 |
Slawa
2005.05.04 11:33
please try send order with wrong prices. You will receive error code not RET_OK. just do it.
|
|
AndrewSchwartz
2005.05.04 12:02
That makes sense, and I am aware of that. I am concerned that I call MtGetPrices to get the prices, then I call MtSendOrder to place the order with the correct price. However, what if the price changes between when I call MtGetPrices and when I call MtSendOrder? Is the broker required to place an order within a certain time period of a MtGetPrices call?
|
|
steve_zhang8
2005.05.05 02:36
It is a really good question. But why I can not find MTSendOrder function? I can only find the SetOrder method, which has no return value.
I am using the metatrader from FxDirect Dealer. Is it the MT3 API? Thanks a lot!! |
|
AndrewSchwartz
2005.05.05 02:41
Yeah, it's in the MT3 API, not in MQL.
|
