Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unrealized Profit for different strategies

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

    Unrealized Profit for different strategies

    Afternoon,

    I am currently trying to get the unrealized profit for my active strategies in an add on, and the number that I get isn't consistent with the Strategies Tab in the Control Center window. This is the code that I am using to get the unrealized profit.

    What do you recommend I use so the number is consistent with the Control Center?


    This is what I am doing.

    double CurrentUnrealizedPNL = 0;

    foreach (StrategyBase strategy in accountSelector.SelectedAccount.Strategies)
    {
    CurrentUnrealizedPNL = strategy.Position.GetUnrealizedProfitLoss(Performa nceUnit.Currency, strategy.Close[0])
    }

    What should I be doing for the number to be accurate?

    #2
    I am using this logic to help determine what todo if my risk ratios are exceeded as a way of automatically turning off the most profitable strategy I have running at the time. So getting an accurate figure is pretty important.

    Comment


      #3
      Hello parkinsonbr,

      Thank you for your reply.

      I believe the issues you are seeing are likely two-fold - first, your use of Close[0] as the price in GetUnrealizedProfitLoss, and secondly, the Calculate setting of your strategies.

      I've created an example indicator that may be of help. It's important to note that within a dispatcher like you'd use to get the account, Close[0] is unreliable at best and using .GetValueAt(idx) where idx is the absolute bar index of the bar will be accurate.

      Next, depending on the Calculate setting of the strategies, you'd only be getting updates using the Close price depending on what that's set to - so for example, if the strategy is set to calculate OnBarClose using the close price of the previous bar may be far off of what the current PnL is.

      I've attached the aforementioned example indicator that will check for strategies on the selected account in chart trader and print their current unrealized pnl to an Output window. The same approach could be used in an add-on.

      Please let us know if we may be of further assistance to you
      Attached Files

      Comment


        #4
        Thanks Kate. I added the line of code to the AddOn and it had a compile which we fixed by adding strategy. to the last close. I have bolded where I updated the line.


        strategy.Position.GetUnrealizedProfitLoss(Performa nceUnit.Currency, strategy.Close.GetValueAt(strategy.CurrentBar)),


        I am testing this today and will let you know if anything else pops up. Thanks again for your help Kate, this appears to have done the trick.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        85 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        143 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        83 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        256 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        334 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X