Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is the correct way to call a custom Performance Metric for use in a Strategy?

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

    What is the correct way to call a custom Performance Metric for use in a Strategy?

    I wrote a custom Performance Metric that I would like to call/reference within a specific strategy. The overall intent is to use the custom Performance Metric as a parameter to halt the strategy (similar to stop strategy code in SampleHaltBasicStrategy or SampleHaltAdvancedStrategy).

    I'm attempting to call the Performance Metric in the same fashion one would call a custom indicator in a strategy. I can get the code to compile, however when I run the strategy I get the "object reference not set to an instance of an object" error. I suspect this is due to how I am calling and/or defining the custom Performance metric within the strategy.

    I'm fairly experienced at coding indicators and strategies in NinjaTrader8, but lack a firm coding foundation in general for C#. That bites me in instances like this.

    If it is not possible to call a custom performance metric from a strategy, that would be helpful to know.

    Thanks in advance for your help.

    Here are the relevant parts of the code for the custom performance metric:

    public class ExampleStrategy : Strategy
    {
    ...
    private DTDeltaRRV0 DeltaRR; //Call DeltaRR custom trade performance parameter like I would a custom indicator

    protected override void OnStateChange()
    {
    else if (State == State.DataLoaded)
    {...
    double[] DeltaRRVal = DeltaRR.Values; //Define custom trade performance parameter like I would a custom indicator
    ...}

    protected override void OnBarUpdate()
    {​...
    double[] DeltaRRVal = DeltaRR.Values; //Set a variable that contains the custom Performance Metric Values
    ...
    if ((DeltaRRVal[0] <= DeltaRRlim
    && this.SystemPerformance.AllTrades.TradesCount >= MinTrades)
    || (this.SystemPerformance.AllTrades.TradesPerformanc e.Currency.CumProfit < MaxLoss
    && this.SystemPerformance.AllTrades.TradesCount < MinTrades))
    {
    //A custom method designed to close all open positions and cancel all working orders will be called.
    //This will ensure we do not have an unmanaged position left after we halt our strategy.

    //StopStrategy();

    // Halt further processing of our strategy
    return;
    }​.​​​

    #2
    Hello whizkpm,

    The help guide does provide sample code.



    Are you looping through the PerformanceMetrics collection?

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea,

      Somehow I had not found those code examples. I think I can figure out my intent from those examples.

      Thanks so much for the help!

      Kevin

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      54 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      71 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X