Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 timko, Today, 06:45 AM
    1 response
    7 views
    0 likes
    Last Post gaz0001
    by gaz0001
     
    Started by Waxavi, 04-19-2024, 02:10 AM
    3 responses
    41 views
    0 likes
    Last Post gaz0001
    by gaz0001
     
    Started by Max238, Today, 01:28 AM
    2 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by Shansen, 08-30-2019, 10:18 PM
    25 responses
    949 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    9 responses
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X