Doesn't private Position position work anymore?

Created at 11 Dec 2013, 20:21
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!
OL

Old Account

Joined 14.10.2013

Doesn't private Position position work anymore?
11 Dec 2013, 20:21


Hi when i use the new  ExecuteMarketOrder insted of Trade.CreateBuyMarketOrder the robot doesn't follow the code inside protected override void OnPositionOpened(Position openedPosition)

Does anyone know how i can fix this ?

Thanks


@Old Account
Replies

Spotware
12 Dec 2013, 09:45

ExecuteMarketOrder uses synchronous operation and you will need to subscribe a callback like in the following example if you want a method to be called when the position opens. This callback method will be called each time a position opens by the robot or manually.

Instead of declaring a field for position you can use Label to identify the position opened by the robot, so that in the event the robot is restarted it can continue operation knowing the positions that it opened. Please read the following section: /forum/whats-new/1937

protected override void OnStart()
{
    Positions.Opened += OnPositionsOpened;
}
 
private void OnPositionsOpened(PositionOpenedEventArgs args)
{
    Print("Position #{0} is opened", args.Position.Id);
}

To find positions by label you can use position.Find and position.FindAll.
See /api/positions
 


 


@Spotware