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!
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
NinjaTrader
Max Profit Per Trade
Collapse
X
-
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.Tags: None
-
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.Chelsea B.NinjaTrader Customer Service
-
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 } }
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
-
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.Chelsea B.NinjaTrader Customer Service
Comment
-
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
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by foxtrott21, Today, 08:27 AM
|
0 responses
1 view
0 likes
|
Last Post
by foxtrott21
Today, 08:27 AM
|
||
Started by jaypelle3, Today, 08:26 AM
|
0 responses
1 view
0 likes
|
Last Post
by jaypelle3
Today, 08:26 AM
|
||
Started by linkcou, Today, 07:01 AM
|
2 responses
19 views
0 likes
|
Last Post
by bltdavid
Today, 08:25 AM
|
||
Started by jaypelle3, Today, 08:25 AM
|
0 responses
2 views
0 likes
|
Last Post
by jaypelle3
Today, 08:25 AM
|
||
Started by jaypelle3, Today, 08:22 AM
|
0 responses
2 views
0 likes
|
Last Post
by jaypelle3
Today, 08:22 AM
|
Comment