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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X