Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Max Profit Per Trade

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

  • NinjaTrader_PatrickH
    replied
    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.

    Leave a comment:


  • PN720
    replied
    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!

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.
    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    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.

    Leave a comment:


  • DuggyLou
    replied
    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.

    Leave a comment:


  • DuggyLou
    replied
    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.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello DuggyLou,

    This would require a custom OptimizationFitness. Something along the lines of MaxNetProfitMinTradesCount.


    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.

    Leave a comment:


  • DuggyLou
    started a topic Max Profit Per Trade

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by wzgy0920, 04-20-2024, 06:09 PM
2 responses
27 views
0 likes
Last Post wzgy0920  
Started by wzgy0920, 02-22-2024, 01:11 AM
5 responses
32 views
0 likes
Last Post wzgy0920  
Started by wzgy0920, 04-23-2024, 09:53 PM
2 responses
49 views
0 likes
Last Post wzgy0920  
Started by Kensonprib, 04-28-2021, 10:11 AM
5 responses
193 views
0 likes
Last Post Hasadafa  
Started by GussJ, 03-04-2020, 03:11 PM
11 responses
3,235 views
0 likes
Last Post xiinteractive  
Working...
X