Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Total Profit & Loss

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Total Profit & Loss

    Hello Community, How are you doing?

    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:
    Code:
    var totalPNL = Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar)
    + Account.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar);
    Approach 2:
    Code:
    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;
    Any of both approaches work fine. It SEEMS that the RealizedProfitNLoss is being updated before the UnrealizedProfitNLoss is being cleaned, and this is not happening at the same time (blocking reads from the Properties), so you get wrong Values.

    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.
    Does anyone was able to do this? faced the same issue and solved it somehow? Thanks in advance.

    #2
    Hello marcosfrank,

    Welcome to the NinjaTrader forum!

    If you are needing to wait until both properties are changed, you may assign event handler methods to the account PostionUpdate, or use a set of bools that waits for the AccountItemUpdate to update with both items and then resets the bools.

    Below are links to the help guide.

    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X