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
      Kate W.NinjaTrader Customer Service

      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 punkiy2111, Today, 05:22 PM
        0 responses
        2 views
        0 likes
        Last Post punkiy2111  
        Started by secrettrader, Today, 03:36 PM
        0 responses
        8 views
        0 likes
        Last Post secrettrader  
        Started by t3chn0, Today, 01:03 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by jleira, Today, 02:27 PM
        0 responses
        25 views
        0 likes
        Last Post jleira
        by jleira
         
        Started by Kreyenhagen, Today, 01:54 PM
        2 responses
        21 views
        0 likes
        Last Post Kreyenhagen  
        Working...
        X