Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

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

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 06-22-2018, 11:24 AM   #1
pel11
Junior Member
 
Join Date: Jun 2018
Posts: 28
Thanks: 0
Thanked 1 time in 1 post
Default Genetic Optimizer Needs to be Penalized

If you run the GO on, say, 1 min bars, and then use a range of 2;20;1 for the variable length of e.g. EMAs of lows and highs with trailstops calculated within the indicator, and then set a variable delta of price range of say 0.01;5;0.01 to execute trades if the stops are breached, the GO will simply make 1 trade if the asset did nothing but go up over the entire period used (1 month). For example, say that on day 1 the price was $50, and on day 30 it was $80 (price went up $1 every day), the GO will simply select an EMA period and price delta to make 1 trade, since it can see that it doesn't need to trade every day -- it recognizes the price went up straight over the 30-day period, and then makes 1 long entry on day 1 and an exit on day 30.

However, using other trading platforms with the same 1 min bars, asset, ranges of parameters, their GO penalizes for doing this and also yields about 10x better net profit and +20-30% winner percentage for dozens of more trades. Based on your GO applied to an intra-day chart, the results are not intraday trading -- more like you need to trade monthly bars. So can you check with your GO developers and ask them why the GO does not penalize for this, while GO's in other platforms don't do this at all?

Couple other things:

You should probably set the default generations to 25, and population size to 100 chromosomes, with a mutation rate of 5%. The default settings essentially don't harness the power of genetic algorithms since the # generations and population size are too small.

Also, do you offer anything that will assist in finding a better ranges of input values, given that your GO doesn't penalize? With your GO, I have to shorten everything and play around with different input parameter ranges.

Last, can I watch fitness as a function of generation? If I can't see winner% or net profit increase with increasing generations, there is no way to judge if the parameters are getting better.
Last edited by pel11; 06-22-2018 at 11:31 AM.
pel11 is offline  
Reply With Quote
The following user says thank you to pel11 for this post:
Old 06-22-2018, 12:49 PM   #2
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 1,727
Thanks: 93
Thanked 468 times in 443 posts
Default

Hello pel11,

Thanks for your post.

I'll be happy to put in a feature request for adding a penalty function to the Genetic Optimizer as well as your suggestion to change the default parameters.

So we can better note this for the development team to look into, could you provide a screenshot of a backtest using a penalty function in another trading platform?

As for finding better ranges of input values, I could not point out a behavior that would provide different ranges outside of comparing tests with normal optimization backtests that test a full range of variables.

For your final question, I am not aware of a way to sort each generations performance in a backtest's results. We could submit this as a suggestion however.

I look forward to being of further assistance.
Last edited by NinjaTrader_Jim; 06-26-2018 at 07:26 AM.
NinjaTrader_Jim is offline  
Reply With Quote
Old 06-25-2018, 03:50 PM   #3
pel11
Junior Member
 
Join Date: Jun 2018
Posts: 28
Thanks: 0
Thanked 1 time in 1 post
Default

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
n(t) = #trades made by optimizer during iteration t
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
File Type: jpg ga_fitness_function_weights.jpg (194.4 KB, 4 views)
Last edited by pel11; 06-25-2018 at 03:55 PM.
pel11 is offline  
Reply With Quote
Old 06-26-2018, 07:31 AM   #4
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 1,727
Thanks: 93
Thanked 468 times in 443 posts
Default

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.
NinjaTrader_Jim is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

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 Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Genetic Optimizer calhawk01 Strategy Development 1 01-16-2018 12:58 PM
Using the Genetic Optimizer kenb2004 Platform Technical Support 5 01-04-2012 05:20 PM
Genetic Optimizer 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.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.