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 argusthome, 03-08-2026, 10:06 AM
|
0 responses
69 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
42 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
24 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
27 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
54 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment