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;
}.

Comment