is there a way to pass the value of a proprietary variable from a strategy to an optimization fitness? I need to calculate the optimization with my own metrics.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Pass the value of a variable to an optimization fitness
Collapse
X
-
This works fine. But, I am getting a problem.
When optimizing, if "aggregated" is checked it doesn't display the Combined result value in the Performance column. Instead, if I use any NT default optimizer, the value appears correctly. For each symbol the value is correct.
I use the code: Value = MyAcumProfit;
Comment
-
Chelsea B.NinjaTrader Customer Service
Comment
-
When using the code:
namespace NinjaTrader.NinjaScript.OptimizationFitnesses
{
public class MyOptimizer : OptimizationFitness
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Optimization Fitness here.";
Name = "MyOptimizer";
}
}
protected override void OnCalculatePerformanceValue(StrategyBase strategy)
{
var myStrategy = strategy as TestStrategy;
if (myStrategy != null)
{
double AcumProfit = myStrategy.MyAcumProfit;
Value = AcumProfit;
}
}
protected override void OnMergePerformanceMetric(PerformanceMetricBase merge)
{
// Cast the merge parameter to the specific type of your optimizer
MyOptimizer targetMetrics = merge as MyOptimizer;
if (targetMetrics != null && TradesPerformance.TradesCount + targetMetrics.TradesPerformance.TradesCount > 0)
{
// Aggregate the values using a weighted average
targetMetrics.Value = (targetMetrics.Value * targetMetrics.TradesPerformance.TradesCount + Value * TradesPerformance.TradesCount) / (TradesPerformance.TradesCount + targetMetrics.TradesPerformance.TradesCount);
}
}
}
}
I get the error: 'NinjaTrader.NinjaScript.OptimizationFitnesses.MyO ptimizer.OnMergePerformanceMetric(NinjaTrader.Ninj aScript.PerformanceMetricBase)': no suitable method found to override
What could be the cause?
Comment
-
guillembm,
Apologies, that was my confusion when glancing at the documentation, this method is for a PerformanceMetric not an OptimizationFitness script.
The PerformanceMetric would be the value that appears in the summary. The OptimizationFitness is used for ranking the optimization results by a metric.
Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
41 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
20 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
28 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
45 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
37 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment