Since the Account.Get(RealizedProfitLoss) gives me the total of all instruments, I'm trying to get it by summing the Executions.
But I get no results.
What could be wrong with the code below:
Dictionary<Order, double> orders = new Dictionary<Order, double>();
foreach(Execution ex in account.Executions) {
if (ex.Instrument.FullName==Instrument.FullName) {
//belongs to order, can be entry or exit
if (!orders.ContainsKey(ex.Order))
orders[ex.Order] = 0;
orders[ex.Order] -= ex.Commission;
if (ex.Order.OrderAction==OrderAction.Buy) {
if (ex.MarketPosition==MarketPosition.Short)
orders[ex.Order] += (ex.Price-ex.Order.AverageFillPrice)*ex.Quantity*50;
} else {
if (ex.MarketPosition==MarketPosition.Long)
orders[ex.Order] += (ex.Order.AverageFillPrice-ex.Price)*ex.Quantity*50;
}
}
double profitloss = 0;
foreach(KeyValuePair<Order, double> kv in orders) {
profitloss += kv.Value;
}
PS: ex.isEntry and ex.isExit don't help either.

Comment