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 geddyisodin, Yesterday, 05:20 AM
    8 responses
    51 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    10 responses
    36 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by DayTradingDEMON, Today, 09:28 AM
    4 responses
    24 views
    0 likes
    Last Post DayTradingDEMON  
    Started by George21, Today, 10:07 AM
    1 response
    17 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by Stanfillirenfro, Today, 07:23 AM
    9 responses
    25 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X