• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Max Profit Per Trade

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

    Max Profit Per Trade

    I'm attempting to analyze some of my strategies. My objective is to be the most profitable with the least amount of trades. In other words Maximum Profit Per Trade. Perhaps I'm missing it but I've tried Max Average Profit and that doesn't seem to be what I'm looking for. Can anybody help me with this? Also a nice feature would be if I could set the number of trades I want to execute then find the most profitable scenario. Or be able to graph # of Trades vs Net Profit in the Multi Objective Optimization Chart.
    Last edited by DuggyLou; 06-25-2017, 03:39 AM. Reason: Additional Information

    #2
    Hello DuggyLou,

    This would require a custom OptimizationFitness. Something along the lines of MaxNetProfitMinTradesCount.
    http://ninjatrader.com/support/helpG...on_fitness.htm

    The Value would need to be a calculation with the strategy.SystemPerformance.AllTrades.TradesCount and with the strategy.SystemPerformance.AllTrades.TradesPerform ance.GrossProfit and strategy.SystemPerformance.AllTrades.TradesPerform ance.GrossLoss.

    I would imagine this would a ratio of the net to trade count but would need to account for negative net profit values.

    Note that the higher the performance Value is set, the higher that result will be the trades that are sorted at the top.

    I would also recommend filtering any results that do not have any trades.
    if (strategy.SystemPerformance.AllTrades.TradesCount < 1)
    Value = -double.MaxValue;

    I would not be able to create a custom algorithm at your request, as in the support department at NinjaTrader it is against our policy to create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients as well as our partners.

    This thread will remain open for any community members that would like to create this custom calculation as a convenience to you.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thanks for your response. I'm looking at the optimization fitnesses in the editor. I'll work with it by choosing "New Optimization Fitness" in the + tab.. And refer to the others as examples and by using the values you suggested.

      Comment


        #4
        Ok, I've got it working. A couple interesting behaviors I've noticed. I was trying to use a couple input parameters but I don't get a dropdown box anywhere in the strategy analyzer. Also I've noticed if I make a change to my optimization fitness and recompile it, the change doesn't actually take effect until I exit NinjaTrader and reopen it.

        Code:
        #region Using declarations
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.ComponentModel.DataAnnotations;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows;
        using System.Windows.Input;
        using System.Windows.Media;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Gui;
        using NinjaTrader.Gui.Chart;
        using NinjaTrader.Gui.SuperDom;
        using NinjaTrader.Gui.Tools;
        using NinjaTrader.Data;
        using NinjaTrader.NinjaScript;
        using NinjaTrader.Core.FloatingPoint;
        
        #endregion
        
        //This namespace holds Optimization fitnesses in this folder and is required. Do not change it. 
        namespace NinjaTrader.NinjaScript.OptimizationFitnesses
        {
        	public class MaxProfitPerTradeFactor : OptimizationFitness
        	{
        		protected override void OnStateChange()
        		{
        			if (State == State.SetDefaults)
        			{
        				Description									= @"Max Profit Per Trade Factor";
        				Name										= "MaxProfitPerTradeFactor";
        				MinTrades					= 5;
        				MaxTrades					= 20;
        //				Name = NinjaTrader.Custom.Resource.NinjaScriptOptimizationFitnessNameMaxProfitPerTradeFactor;
        			}
        			else if (State == State.Configure)
        			{
        			}
        		}
        
        		protected override void OnCalculatePerformanceValue(StrategyBase strategy)
        		{
        			if (strategy.SystemPerformance.AllTrades.TradesCount < MinTrades || strategy.SystemPerformance.AllTrades.TradesCount > MaxTrades)
        			{
        				Value = -double.MaxValue;
        			}
        			else
        				Value = (double)((strategy.SystemPerformance.AllTrades.TradesPerformance.GrossProfit + strategy.SystemPerformance.AllTrades.TradesPerformance.GrossLoss)/strategy.SystemPerformance.AllTrades.TradesCount);
        		}
        
        
        		#region Properties
        		[NinjaScriptProperty]
        		[Range(1, int.MaxValue)]
        		[Display(Name="MinTrades", Order=1, GroupName="Parameters")]
        		public int MinTrades
        		{ get; set; }
        
        		[NinjaScriptProperty]
        		[Range(1, int.MaxValue)]
        		[Display(Name="MaxTrades", Order=2, GroupName="Parameters")]
        		public int MaxTrades
        		{ get; set; }
        		#endregion
        
        	}
        }
        Also when you set ...

        Value = -double.MaxValue;

        you aren't nullifying that data. You are simply assigning that parameter set permutation a negative value that essentially hides unwanted data from the output results. Correct?
        Last edited by DuggyLou; 06-27-2017, 10:58 AM.

        Comment


          #5
          Hello DuggyLou,

          I am also experiencing that properties are not appearing in the strategy analyzer for this.
          I've reported this to our development. Once I have a tracking ID for this behavior I will post in this thread.

          However, testing with prints, I am showing that my compiled changes are effective without restarting.
          https://www.screencast.com/t/UalOMscV

          Last, you nailed it. I'm sending results with no trades to the bottom of the ranking by setting the performance to the lowest possible value.

          The idea with the value being set, is you want to know what had the best performance for lowest trades. No need to add results without any performance.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello DuggyLou,

            I've checked with our development who has let me know optimization fitness parameters are not supported and this will be removed from future versions of NinjaTrader as well as the help guide.

            This is being tracked with ID #NTEIGHT-11922.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hey guys,

              I just wanted to say that this code was exactly what I was looking for.

              Please add this as a standard Optimization Finesse moving forward. I do wish we could customize the Min and Max Trades through Input Parameters though without having to edit the source code.

              Thanks!

              Comment


                #8
                Hello PN720,

                Thank you for your post.

                Your vote for this feature has been added to the internal tracking id of SFT-3216.

                Please let me know if you have any questions.
                Patrick H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cirzonorkecv, Yesterday, 11:52 PM
                0 responses
                1 view
                0 likes
                Last Post cirzonorkecv  
                Started by rickyblah12, Yesterday, 01:01 PM
                1 response
                12 views
                0 likes
                Last Post Erwin Beckers  
                Started by dadarara, Yesterday, 12:18 PM
                0 responses
                8 views
                0 likes
                Last Post dadarara  
                Started by joemiller, Yesterday, 07:33 AM
                2 responses
                12 views
                0 likes
                Last Post joemiller  
                Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
                7 responses
                38 views
                0 likes
                Last Post DaveS
                by DaveS
                 
                Working...
                X