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 Hwop38, 05-04-2026, 07:02 PM
|
0 responses
160 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by CaptainJack, 04-24-2026, 11:07 PM
|
0 responses
307 views
0 likes
|
Last Post
by CaptainJack
04-24-2026, 11:07 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
244 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
348 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
178 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|

Comment