I would like to see PL of the given IOrder (assuming it was either a position entry, closed by a corresponding exit order, or, an exit order, with a corresponding entry order).
Please confirm that the following code is correct way for doing that:
I am talking about unmanaged code
private bool TryGetOrderPL(IOrder order, bool asEntry, out double pl)
{
bool found = false;
pl = 0.0;
for (int i = Performance.AllTrades.Count - 1; i >= 0; i--)
{
Trade trade = Performance.AllTrades[i];
bool me = (asEntry ? trade.Entry.Order : trade.Exit.Order) == order;
if (me)
{
found = true;
pl += trade.ProfitCurrency * trade.Quantity;
}
}
return found;
}

Comment