protected override void OnAccountItemUpdate(Cbi.AccountItemEventArgs accountItemUpdate) { if (AccountName != Account.SimulationAccountName || accountItemUpdate.Account.Name != AccountName || accountItemUpdate.AccountItem != AccountItem.RealizedProfitLoss) { return; } accountDenomination = accountItemUpdate.Account.Denomination; executions.Clear(); foreach (Cbi.Execution execution in accountItemUpdate.Account.Executions) { if (execution.Instrument == Instrument || (execution.Instrument.MasterInstrument.InstrumentType == InstrumentType.Stock && execution.Instrument.FullName == Instrument.FullName)) { executions.Add(execution); } } CurrentValue = Cbi.SystemPerformance.Calculate(executions).AllTrades.TradesPerformance.Currency.CumProfit; }
protected override void OnAccountItemUpdate(Cbi.AccountItemEventArgs accountItemUpdate) { if (AccountName != Account.SimulationAccountName || accountItemUpdate.Account.Name != AccountName || accountItemUpdate.AccountItem != AccountItem.UnrealizedProfitLoss) { return; } lock (accountItemUpdate.Account.Positions) position = accountItemUpdate.Account.Positions.FirstOrDefault(o => o.Instrument.FullName == Instrument.FullName); executions.Clear(); foreach (Cbi.Execution execution in accountItemUpdate.Account.Executions) { if (execution.Instrument == Instrument) { executions.Add(execution); } } realizedPL = Cbi.SystemPerformance.Calculate(executions).AllTrades.TradesPerformance.Currency.CumProfit; CurrentValue = realizedPL + (position == null ? 0 : position.GetUnrealizedProfitLoss(Cbi.PerformanceUnit.Currency)); }