detect if a position close by stoploss or by takeprofits
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;
}
firemyst
24 Jun 2023, 17:41
Use "args.Reason" to find the reason a position was closed.
@firemyst