CTrade ResultPrice - no value for pending order executed

 

Hi all,

I'm using the CTrade class to place a pending order and retrieve the executed price when the order gets executed, however I keep getting a value of 0.

This is the MqlTradeResult I get :

MqlTradeResult{  retcode:10009 deal:0 order:2 volume:1.47 price:0.0 bid:11766.129999999999199645 ask:11767.129999999999199645 comment:"Request executed" request_id:0 retcode_external:0 reserved:[124] }.

Having the TicketId (ResultOrder), I even checked through HistoryOrderGetInteger to see if the order was filled, and yet I still get 0.

ulong lTicketID = oTrade.ResultOrder();
ENUM_ORDER_STATE  eState    = (ENUM_ORDER_STATE)HistoryOrderGetInteger(lTicketID, ORDER_STATE);
if(eState == ORDER_STATE_FILLED)
{
            MqlTradeResult oResult;
            oTrade.Result(oResult);
}

When I place a market order, the ResultPrice is populated though.

How can I get the price at which my pending order was executed ?

Thanks,

sk

 

Ok, so one workaround, seems to just get the deal through :

HistoryDealSelect(lTicketID);
double dExecutedPrice = HistoryDealGetDouble(lTicketID, DEAL_PRICE);                

However, how can I make sure, that this deal corresponds to my ticket order, without looping through the whole deal list and finding the one associated with order number lTicketID.

Is the Deal ID the same as the Order ID ?

 
Skullnick:

Ok, so one workaround, seems to just get the deal through :

However, how can I make sure, that this deal corresponds to my ticket order, without looping through the whole deal list and finding the one associated with order number lTicketID.

Is the Deal ID the same as the Order ID ?

Use OnTrade() or OnTradeTransaction()
 
Hi Alain,
This would be the best solution, but unfortunately I need to update my system once an order has been executed before the OnTick() event handler is called. And its not possible to set a priority between Event handlers, as I’d like OnTradeTransaction to supercede OnTick.
 
Skullnick:
Hi Alain,
This would be the best solution, but unfortunately I need to update my system once an order has been executed before the OnTick() event handler is called. And its not possible to set a priority between Event handlers, as I’d like OnTradeTransaction to supercede OnTick.
Use a semaphore. Set to true an order is send, to false when "recognized" in OnTrade(). If false don't run OnTick() as it means your order is not yet processed (or at least the terminal is not yet aware about it).