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

Need help with using SystemPerformance in Custom Add-In

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

    Need help with using SystemPerformance in Custom Add-In

    Hello,

    I need help using SystemPerformance, I am trying to use the SystemPerformance features in an custom add-in i develop, my add-in inherits from the NinjaTrader.Gui.Tools.NTTabPage namespace, when i instantiate and try to use SystemPerformance class the results are zero, the trade count are also zero.


    I tried adding it in the OnBarUpdate function too, doesn't work there either. Am i missing something? Need the ability to get the ticks, and Pnl, after the position has closed out, for any instrument? I can't get this information when position is closed because it is null. Is there another way to get the PnL, and ticks whether in position or not? Is there way to get trades, or transaction information, isn't this what the systemperformance feature is for? Also please note, my implmention is an add-in not a strategy, etc all order are places using limit, and or market order Account.Orders.Submit function


    Code:
    if (isInPosition)
     {
                    // GetUnrealizedProfitLoss
                    var PnL_UnRealized_ByTicker = objPosition.GetUnrealizedProfitLoss(PerformanceUnit.Currency);
                    var Ticks_UnRealized_ByTicker = objPosition.GetUnrealizedProfitLoss(PerformanceUnit.Ticks);
                    var Percent_UnRealized_ByTicker = objPosition.GetUnrealizedProfitLoss(PerformanceUnit.Percent);
    }​
    Code:
    else
    {
    var alltradesCollCount = _Trades.Count; // SystemPerformance.AllTrades.Count;
                var alltradesTradeCount = _Trades.TradesCount; // SystemPerformance.AllTrades.TradesCount;
    
                var allTradesPnLTicks = this.getAllTradesPnLTicks();
                var allTradesPnLCurrency = this.getAllTradesPnLCurrency();
    
                Debug.WriteLine($"alltradesCollCount: {alltradesCollCount}");
                Debug.WriteLine($"alltradesTradeCount: {alltradesTradeCount}");
    
                Debug.WriteLine($"allTradesPnLTicks: {allTradesPnLTicks}");
                Debug.WriteLine($"allTradesPnLCurrency: {allTradesPnLCurrency}");​
    }
    Code:
    private double getAllTradesPnLCurrency()
            {
                var trades = systemPerformance.AllTrades.Where(x => x.Exit.Instrument.FullName == Instrument.FullName);
                if (trades.IsNullOrEmpty()) return 0;
                return trades.Last().ProfitCurrency;
    
                // return trades.Last().ProfitCurrency;
                // return trades.Last().ProfitTicks;
                // return trades.Last().ProfitPercent;
            }
            private double getAllTradesPnLTicks()
            {
                var trades = systemPerformance.AllTrades.Where(x => x.Exit.Instrument.FullName == Instrument.FullName);
                if (trades.IsNullOrEmpty()) return 0;
                return trades.Last().ProfitTicks;
                // return trades.Last().ProfitCurrency;
                // return trades.Last().ProfitTicks;
                // return trades.Last().ProfitPercent;
            }​

    #2
    Hello digitalsolvers,

    Thank you for your post.

    The SystemPerformance object only holds data related to trades and trade performance information from a strategy and not from an add-on. This is why it is included in the Strategy sub-section in the help guide:For an add-on, you could consider subscribing to AccountItemUpdate events and tracking certain AccountItems to store and use those values for your own performance calculations:For example, you could get the AccountItem.UnrealizedProfitLoss and then you would have to calculate the number of ticks based on the TickSize for each instrument in which a position is held. To get an idea of how some statistics are calculated, you could view the Statistics Definitions here:


    We also have a page that covers Profit and Loss Calculation Modes here:


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ageeholdings, Today, 07:43 AM
    0 responses
    6 views
    0 likes
    Last Post ageeholdings  
    Started by pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    12 views
    0 likes
    Last Post burtoninlondon  
    Working...
    X