detect if a position close by stoploss or by takeprofits

Created at 17 Apr 2014, 15:16
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!
Paulo_Lira's avatar

Paulo_Lira

Joined 12.02.2014

detect if a position close by stoploss or by takeprofits
17 Apr 2014, 15:16


Let us now when a position was close by takeprofits for instantanealy open another position with same tradetype

private void OnPositionsClosed(PositionClosedEventArgs args)
{
var closedPositionInfo = args.Position;

if (lastposId == closedPositionInfo.Id) {

if ((closedPositionInfo.StopLoss == Symbol.Bid) || (closedPositionInfo.StopLoss == Symbol.Ask)){
Print ("last position closed by stoploss");
} else if ((closedPositionInfo.TakeProfit == Symbol.Bid) || (closedPositionInfo.TakeProfit == Symbol.Ask)){
Print ("last position closed by takeprofits");
} else {
Print ("we do not know why...");
}

}

closedPositionInfo = null;
}


cTrader Automate
@Paulo_Lira
Replies

firemyst
24 Jun 2023, 17:41

Use "args.Reason" to find the reason a position was closed.

 

 private void OnPositionsClosed(PositionClosedEventArgs args)
        {
         Print("Closed for reason {0}", args.Reason);
        }

 


@firemyst