MT3 API Questions

To add comments, please log in or register
Forex Trader
114511
Forex Trader  
I am using the C++ version of the MT3 api. I have 2 problems/questions:

1. Closing orders. I have 2 sockets in my application, one in pumping mode and the other I open and close as needed. When I close an order on the second socket, I get an UPDATE_TRADES message on the pumping socket. When I call GetTradeRecords(), it returns an array of open trades. By comparing this array to the array I have of open trades, I can infer which trade was closed. My problem is, how do I determine what price and time this trade was closed at? If I am closing the order myself, I know what price I wanted to close the order at, but what about slippage? Also, if the order is closed from the MQ Client, I get the same notification, but have no idea what price the order was closed at.

I know I can call GetTradeHistory(), but that seems expensive.

2. When I try to close an order programatically, I do something like this:

open socket
call GetPrices( symbol, lots, &bid, &ask );
if( openOrder is a buy )
    price = bid;
else
    price = ask;

call CloseOrder( orderId, price, lots );



The CloseOrder call always returns an error of 2 (RET_ERROR).

I have tried inserting a ::Sleep( 5000 ) between the GetPrices call and the CloseOrder call, but I get the same result.

If I set the close price manually, without calling GetPrices, the CloseOrder call works fine. Any suggestions?

Thanks,

Steve

Forex Trader
114511
Forex Trader  
1. GetTradeHistory is only one way. You can call GetTradeHistory for last day only

2. GetPrices used for request execution mode only. For instant executuion use current bid or ask
To add comments, please log in or register