know how position was closed
Created at 09 Apr 2025, 11:13
know how position was closed
09 Apr 2025, 11:13
Is there a way to look at past position and know how it was closed - stop loss, take profit or closed by user/cBot?
I'm looking for a way to know what informarion by GUI or by code after the bot was finished.
Thanks
firemyst
10 Apr 2025, 00:25
You have to use the Positions.Closed event handler to obtain the reason a position was closed. This means you can't really go back in time since the event happens when the position is closed.
Ex:
Positions.Closed += Positions_Closed;
private void Positions_Closed(PositionClosedEventArgs args)
{
Position p1 = args.Position;
//make sure you isolate and get your position since the event method is called for any position that's closed
if (p1.SymbolName == Symbol.Name && p1.Label == _positionLabel)
{
Print("PC06: Position \"{0} {1}\" closed for reason \"{2}\" with {3} profit. ", p1.Id, p1.Label, args.Reason, String.Format("{0:$#,###.00}", p1.GrossProfit));
}
}
@firemyst