DR
Refer to last closed position
18 Feb 2018, 14:37
Hi All,
I want to close all open positions if one position hits it's stop loss, the code below seems logical but I fear it is outdated... What would the current approach be?
var lastPosition = Trade.Result.Last(1);
if (lastPosition.NetProfit < 0)
{
foreach (Position position in symbolSearch)
{
ClosePosition(position);
}
}

PanagiotisCharalampous
20 Feb 2018, 11:53
Hi Drummond360,
You might consider something like the below
protected override void OnStart() { Positions.Closed += OnPositionsClosed; } void OnPositionsClosed(PositionClosedEventArgs obj) { if (obj.Position.NetProfit < 0) { foreach (var position in Positions) { ClosePosition(position); } } }However note that the code above does not guarantee that the position has been closed by a stop loss. It could be a manual close as well.
Best Regards,
Panagiotis
@PanagiotisCharalampous