I'm working with a strategy that needs to calculate the total profit and loss (realized + unrealized). And I found out that the way that I was doing that, it's not working.
Approach 1:
var totalPNL = Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) + Account.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar);
List<Execution> executions = Account.Executions.ToList(); SystemPerformance systemPerformance = SystemPerformance.Calculate(executions); var realizedPNL = systemPerformance.RealTimeTrades.TradesPerformance .Currency.CumProfit; var unrealizedPNL = PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Currency); var totalPNL = realizedPNL + unrealizedPNL;
Let's imagine the following example:
Millisecond | Realized PnL | Unrealized PnL | Total PnL | Observation |
1 | 40 | 10 | 50 | OK. |
2 | 50 | 10 | 60 | Closing Position.Error. |
3 | 50 | 0 | 50 | Back to OK. |
Comment