ExexcuteMarketOrder not working properly

Created at 26 Jan 2014, 11:41
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
GI

giovi61

Joined 26.01.2014

ExexcuteMarketOrder not working properly
26 Jan 2014, 11:41


Hi, I'm a bit of time studying the creation of robots. I have a problem with the new method compared to ExexcuteMarketOrder Trade.CreateBuyMarketOrder and Trade.CreateSellMarketOrder. In fact, replacing the old-fashioned method with the new results in backtesting are different.


@giovi61
Replies

Spotware
27 Jan 2014, 10:04

The difference is that the old API methods are using asynchronous execution whereas ExecuteMarketOrder uses synchronous execution.

If you want to compare the two you can use ExexcuteMarketOrderAsync which uses asynchronous execution. Bear in mind that if you used OnPositionOpened with Trade.CreateBuyMarketOrder, you will have to define a callback method for ExecuteMarketOrderAsync that will be invoked when the position opens.
For instance:

protected override void OnStart()
{
    ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 10000, "My Label", OnExecuted);
}
 
private void OnExecuted(TradeResult result)
{
    if (result.IsSuccessful)
    {
        Print("Position created entry price: {0}", result.Position.EntryPrice);
    }
    else
    {
        Print("Failed to create position");
    }
}

Please read  /forum/whats-new/1937 as well as /api/guides/trading_api for more information.


@Spotware