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 NullPointStrategies, Today, 05:17 AM
    0 responses
    38 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X