NinjaTrader Support Forum Genetic Optimizer Needs to be Penalized

 Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

 The following user says thank you to pel11 for this post:
06-25-2018, 03:50 PM   #3
pel11
Junior Member

Join Date: Jun 2018
Posts: 28
Thanks: 0
Thanked 1 time in 1 post

Jim,

Probably send this to the genetic algorithm (GA) developers:

Assume:

1. you are running the Strategy Optimizer on 5 days of 1-minute bars (daytime sessions).
2. also assume that the price return (e.g., Close) of the asset (future, forex, stock) went up straight every day almost forming a straight line over all the 1-minute bars.

Problem: (which is what I noticed with the GA optimizer):

When using a custom indicator (strategy) to determine programmed trailing stops on the Lows and Highs, if the range in NT8 is for example 5;30;1 in the strategy optimizer, for this type of stock only 1 trade will be made with an entry the morning of the first day, and an exit near the close of session on the last day.

This is because of the fitness function, and the fact that the GA noticed only 1 trade needed to be made. I do not see this in Amibroker's optimizer (particle swarm optimization) or in Wealth Labs GA optimizer. Instead it seems these other GA's are going down in the "weeds" and looking for more trades.

What could be done is to penalize for a low number of trades or too many trades, but it requires that the user has an option called "Reward for #trades: ".

Say I optimized with another platform and obtained very a profitable daily profit factor (or cum net profit) which resulted in about 5 trades per day, or 25 trades for the 5 days. Either that, or a user wants to reward the GA for 25 trades over 5 days. The user would enter 25, and then your code would do the following:

Let:

t = iteration in optimizer run
d = the number of trades desired, to reward over the backtest period
x(t) = -3+(n(t) -1)*6/d (intermediate number, actually a standard normal variate)

the weight for iteration t is then

w(t) = 1/sqrt(2*Math.Pi) * Math.Exp(-0.5*x(t)^2)

A plot of w(t) as a function of the #trades the optimizer makes per iteration for 25 desired trades is attached. w(t) should be multiplied by the value of the GA fitness function for iteration t.

Recall, the other GA optimizers I use do not make 1 trade when very long periods are in the range of the parameters, but the NT8 GA seems to bite on the single trade. So they are doing something to penalize for a low number of trades.
Attached Images
 ga_fitness_function_weights.jpg (194.4 KB, 4 views)
Last edited by pel11; 06-25-2018 at 03:55 PM.

 06-26-2018, 07:31 AM #4 NinjaTrader_Jim NinjaTrader Customer Service     Join Date: Nov 2016 Location: Denver, CO Posts: 1,727 Thanks: 93 Thanked 468 times in 443 posts Thanks pel11, That information helps. I have included this with the a feature request for a penalty function. Here are the ticket ID's for the feature requests submitted. SFT-3313 Penalty function for Genetic Optimizer SFT-3314 Ability to sort GO backtest results by generation number SFT-3315 Request for new default GO properties Feature request interest is aggregated before it is determined if the feature should be implemented, so we can't offer an ETA. Upon implementation, the number for the ticket IDs can be found publicly on the Release Notes page of the help guide. I'll provide a link below. Release Notes: https://ninjatrader.com/support/help...ease_notes.htm If there is anything else we can do to help, please let us know. JimNinjaTrader Customer ServiceUse Kinetick, NinjaTrader’s preferred market data service - Learn MoreFree online training events - View Schedule

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News and Announcements     News and Announcements NinjaTrader 8     Platform Technical Support     Add-On Development     Indicator Development     Strategy Development NinjaTrader 7     Platform Technical Support     General Development     Indicator Development     Strategy Development NinjaScript File Sharing     NinjaScript File Sharing Discussion     Version 8 Add-Ons     Version 8 Indicators     Version 8 Strategies     Version 7 Indicators     Version 7 Strategies     Version 7 Miscellaneous NinjaScript Educational Resources     Reference Samples     Tips Suggestions and Feedback     Suggestions And Feedback Historical Beta Archive     Version 8 Beta

 Similar Threads Thread Thread Starter Forum Replies Last Post calhawk01 Strategy Development 1 01-16-2018 12:58 PM kenb2004 Platform Technical Support 5 01-04-2012 05:20 PM Pete S NinjaScript File Sharing Discussion 18 08-22-2008 12:16 AM

All times are GMT -6. The time now is 01:45 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.