What is the default value of order ticket? Is checking order ticket's value a proper way to confirm a market order is filled?
I use such a construction (it is in all my recent advisor codes in CodeBase).
if(m_trade.Buy(long_lot,m_symbol.Name(), m_symbol.Ask(),sl,tp)) // CTrade::Buy -> "true" { if(m_trade.ResultDeal()==0) { if(m_trade.ResultRetcode()==10009) // trade order went to the exchange { SPosition[index].waiting_transaction=true; SPosition[index].waiting_order_ticket=m_trade.ResultOrder(); } else { SPosition[index].waiting_transaction=false; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", ERROR: ","#1 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); } if(InpPrintLog) PrintResultTrade(m_trade,m_symbol); } else { if(m_trade.ResultRetcode()==10009) { SPosition[index].waiting_transaction=true; SPosition[index].waiting_order_ticket=m_trade.ResultOrder(); } else { SPosition[index].waiting_transaction=false; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","#2 Buy -> true. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); } if(InpPrintLog) PrintResultTrade(m_trade,m_symbol); } } else { SPosition[index].waiting_transaction=false; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", ERROR: ","#3 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); if(InpPrintLog) PrintResultTrade(m_trade,m_symbol); }
You shouldn't care. If the operation fails, what good is the ticket number? If the operation succeeds, get it.
I use such a construction (it is in all my recent advisor codes in CodeBase).
Thank you for sharing.
I'm not sure how does "SPosition[index].waiting_transaction" work.
My understanding is that your method is to check the result code after sending a market order successfully. If the result code is 10009 then proceed, and if not, wait for a while then check again. Is my understanding correct?
You shouldn't care. If the operation fails, what good is the ticket number? If the operation succeeds, get it.
Thank you for your reply.
You are right but my concern is not only when operation fails. In cases when the position is successfully opened, if I try to fetch and store the ticket number right after the PositionOpen() function, it might be too quick that I can't get the correct result(*). So I want to make sure the trade operation is correctly placed then get information such as ticket number.
I would appreciate it if you have any advices/suggestions such as checking the result code.
Thank you for sharing.
I'm not sure how does "SPosition[index].waiting_transaction" work.
My understanding is that your method is to check the result code after sending a market order successfully. If the result code is 10009 then proceed, and if not, wait for a while then check again. Is my understanding correct?
Yes, right. The result in case of a successful order placement is expected in OnTradeTransaction.
Yes, right. The result in case of a successful order placement is expected in OnTradeTransaction.
Thank you.
I will check the OnTrade approach.
Have a nice day:)

- 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 everyone!
I am using CTrade library to open a long position at the market price then get the order ticket number.
The CTrade document says "Successful completion of the PositionOpen(...) method does not always mean successful execution of the trade operation.", so I want to check if the order is filled.
My question is : Is the default value(before filled) of an order ticket zero? If it is, I want to use the following code to confirm and get the order ticket number. Is it appropriate?
*Furthemore: Is the default value(before opened) of a position ticket also zero? I might use RequestPosition() to check if a new position is successfully opened and get the position ticket number too.
Thank you very much!!