I'm struggling to pass variable values from a strategy to a custom optimization fitness. I want to access public custom variables defined in my strategy within the fitness function, rather than relying solely on SystemPerformance values.
Current Optimization Fitness Code Snippet:
namespace NinjaTrader.NinjaScript.OptimizationFitnesses
{
public class MaxPrecisionFitness : OptimizationFitness
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Optimization Fitness here.";
Name = "Max. Precision";
}
else if (State == State.Configure)
{
}
}
protected override void OnCalculatePerformanceValue(StrategyBase strategy)
{
Value = (double) strategy.SystemPerformance.LongTrades.Count/strategy.SystemPerformance.AllTrades.Count;
}
}
}
Goal:
1. Define public custom variables in my strategy (e.g., myVariable)
2. Access these variables in a custom optimization fitness function
3. In the code above, the idea is to use custom trade collections (e.g, fpTrades or tpTrades) from strategy and count the number of trades within the optimization fitness logic.
Questions:
1. How can I pass strategy variables to the custom fitness function?
2. Is there a specific interface or base class I need to implement?
Any guidance or examples would be greatly appreciated!

Comment