Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom OptimizationFitnesses function and use it in WFO/Optimization?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom OptimizationFitnesses function and use it in WFO/Optimization?

    Is it possible to create your own OptimizationFitnesses function and use it in WFO for example?

    Custom Metric=w1​×(Max Net Profit)+w2​×(Max Profit Factor)

    Where w1​ and w2​ are the weights you assign to Max Net Profit and Max Profit Factor, respectively. These weights can be adjusted based on how much importance you want to give to each metric.




    Code:
    namespace NinjaTrader.NinjaScript.OptimizationFitnesses
    {
        public class MaxProfitFactor : OptimizationFitness
        {
            protected override void OnCalculatePerformanceValue(StrategyBase strategy)
            {
                Value = strategy.SystemPerformance.AllTrades.TradesPerformance.ProfitFactor;
            }
    
            protected override void OnStateChange()
            {              
                if (State == State.SetDefaults)
                    Name = NinjaTrader.Custom.Resource.NinjaScriptOptimizationFitnessNameMaxProfitFactor;
            }
        }
    }​
    Code:
    namespace NinjaTrader.NinjaScript.OptimizationFitnesses
    {
        public class MaxNetProfit : OptimizationFitness
        {
            protected override void OnCalculatePerformanceValue(StrategyBase strategy)
            {
                Value = strategy.SystemPerformance.AllTrades.TradesPerformance.GrossProfit + strategy.SystemPerformance.AllTrades.TradesPerformance.GrossLoss;
            }
    
            protected override void OnStateChange()
            {              
                if (State == State.SetDefaults)
                    Name = NinjaTrader.Custom.Resource.NinjaScriptOptimizationFitnessNameMaxNetProfit;
            }
        }
    }​

    #2
    Hello prisonbreaker82,

    Thank you for your post.

    You could certainly create your own Optimization Fitness metric that performs calculations such as the formula you mentioned in OnCalculatePerformanceValue():
    Custom Metric=w1​×(Max Net Profit)+w2​×(Max Profit Factor)

    As for your comment "These weights can be adjusted based on how much importance you want to give to each metric." The weights would have to be adjusted programmatically. If you wanted to change the weights, you would have to go in and change the script for the optimization fitness metric or you would have to save multiple versions with different weights applied. There is an example script in the platform for SampleCumProfit that you may review and I also suggest viewing this section of the help guide for more info on Optimization Fitness scripts:For a list of different statistic definitions and basic information about how they are calculated, please see the following help guide page:
    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    38 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X