NexusFi: Find Your Edge


Home Menu

 





NinjaTrader Genetic Optimizer


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one piersh with 49 posts (94 thanks)
    2. looks_two Big Mike with 26 posts (10 thanks)
    3. looks_3 TraderDJB with 13 posts (18 thanks)
    4. looks_4 dsraider with 10 posts (0 thanks)
      Best Posters
    1. looks_one piersh with 1.9 thanks per post
    2. looks_two TraderDJB with 1.4 thanks per post
    3. looks_3 sam028 with 0.5 thanks per post
    4. looks_4 Big Mike with 0.4 thanks per post
    1. trending_up 91,614 views
    2. thumb_up 134 thanks given
    3. group 47 followers
    1. forum 197 posts
    2. attach_file 19 attachments




 
Search this Thread

NinjaTrader Genetic Optimizer

  #1 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120

Latest version (1.12), with NT7 support, is here

Hi All,

I've created a new Genetic Strategy Optimizer based loosely on Peter's GAOptimizer.


Installation Instructions:
- download the .ZIP file from the download link (above). NOTE: ignore the '1.09' in the filename - it's wrong, but i can't change it...
- in the main NT window, choose the "File->Utilities->Import NinjaScript" menu.
- when prompted, locate the downloaded .ZIP file
- in your strategy analyzer optimize dialog choose "PH Genetic" as the Optimizer.
- you can select whichever "Optimize on..." metric you like.
- when the "PH Genetic Options" dialog appears, hover over the controls to get a short description of what each option does.
- if you upgrade NT6.5, you'll need to re-install or uninstall the optimizer.

like most GA optimizers it does like to find a local maximum, although it'll attempt to kick out if it notices stability.

let me know if you have any problems/questions. i'll write some documentation soon, honest ;-)

- more info what's new here.
- brief instructions on how to optimize Enum values in your strategies, here.

Attached Thumbnails
Click image for larger version

Name:	Screenshot.png
Views:	1436
Size:	7.5 KB
ID:	153   Click image for larger version

Name:	Screenshot v1.03.png
Views:	2321
Size:	14.7 KB
ID:	1648  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
20 thanks
  #2 (permalink)
 
wh's Avatar
 wh 
Neubrandenburg, Germany
 
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks Given: 298
Thanks Received: 512

please use this else error when you do on explorer ...
C:\Users\trading\Documents\NinjaTrader 6.5\bin\Custom\Strategy>rename @Strategy.cs @Strategy.cs.bak

Reply With Quote
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


It looks nice, but what did you add/modify ?
Is the % of Aliens are a random elements added during the selection process ?
Anyway, I'll test it, thx Piersh.

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120


sam028 View Post
It looks nice, but what did you add/modify ?
Is the % of Aliens are a random elements added during the selection process ?
Anyway, I'll test it, thx Piersh.

hi sam, it's pretty much a complete rewrite:
  • it uses a different way of extracting the tested strategy's score. it uses a hack in base Strategy.Dispose to get around a design flaw in NT - they don't expose the value being optimized to the optimizer . this allows you to use whichever scoring metric you like without modification. i removed the logging/threshold stuff since this it uses the same scoring as the analyzer. you can add this in your custom OptimizationTypes, if necessary.
  • it uses an integral representation of the parameter space that allows it to ensure that all children are unique - reducing the number of backtest runs that are required.
  • it uses a fitness weighting function to more naturally choose the parents of the next generation. the chance that an individual gets to procreate is on a probability curve, not a boolean function. this increases the richness of the gene pool by allowing worse-performing individuals to procreate (albeit with lower probablility than others)
  • it makes an attempt to determine when a maximum has been found and the parameter space is stable (ie. subsequent generations are unlikely to produce any better individuals). it does this by checking the top 'stability size' % of the population - if they're the same between two generations, then it considers the parameter space to be stable. at this point it blows away (almost) the whole history and starts over with the top 'reset size' % of the previous lot, seeds the rest of the new generation with aliens and continues. if you find it's resetting too much, try increasing the 'stability size' percentage (a value of 100 means it'll never reset).
  • between resets, it creates new generations from all previous generations. this is necessary since new children are now unique. i might add an aging function to reduce the probability of those crusty great-great-great-grandparents getting some action...
  • it adds aliens. aliens are completely randomly generated (none of their genes are derived in any way from other individuals). a certain configurable percentage of every new generation are aliens, the rest are normal (possibly mutated) children of the previous generations. I added this because I found that while it slows convergence somewhat, it allows a broader search of the parameter space, helping to avoid local maximums.

i have found, at least with the strategy i'm using to test with and fine-grained parameter settings (2 billion individuals), that the parameter surface is very bumpy and the algorithm likes to get caught at the top of some local maximum without getting closer to the optimal set. it'll find a good solution quickly, but not necessarily the best.

Reply With Quote
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,399 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,539

This looks really interesting!


Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 goforbroke01 
Chicago
 
Experience: Intermediate
Platform: NT
Broker: IB
Posts: 11 since Jun 2009
Thanks Given: 8
Thanks Received: 1

Piersh

Great work! I have a question - do you have a way of making this compatible with the NT walk forward function? Currently, every time it rolls forward, it stops and waits for user input to confirm the GO parameters

thanks

Reply With Quote
  #7 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120


goforbroke01 View Post
Piersh

Great work! I have a question - do you have a way of making this compatible with the NT walk forward function? Currently, every time it rolls forward, it stops and waits for user input to confirm the GO parameters

thanks

oops, sorry i hadn't tried with walkforward. i've uploaded a new version (to the original post above) which should help a little. please let me know if it still doesn't work for you.

Reply With Quote
  #8 (permalink)
 goforbroke01 
Chicago
 
Experience: Intermediate
Platform: NT
Broker: IB
Posts: 11 since Jun 2009
Thanks Given: 8
Thanks Received: 1

Piersh

thanks for the fix - runs ok except that after the first full run through, subsequent runs don't display the GO params form. It may be that the walkthrough flag persists, not being reset after the job is complete.

-thanks

Reply With Quote
  #9 (permalink)
 
Peter's Avatar
 Peter 
Brisbane; Australia
 
Experience: Intermediate
Platform: NT
Broker: IB/TDA needing new broker
Trading: Futures, Forex, Stocks
Posts: 97 since Jun 2009
Thanks Given: 91
Thanks Received: 118

Piersh, thanks a lot for this. First time user of GO and am very very impressed. Could have saved me weeks in working with the NT built-in. Finally my computer can work with 6 parameters at once instead of just 3 and that in a fraction of the time..

I saw a mail from -Swig- on the NT forum about optimizing e.g. running multiple moving averages via a trick of assigning numbers to the MAs. Did you ever try that with your GO?

Reply With Quote
Thanked by:
  #10 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120



Peter View Post
I saw a mail from -Swig- on the NT forum about optimizing e.g. running multiple moving averages via a trick of assigning numbers to the MAs. Did you ever try that with your GO?

Yes indeed, I use Swig's neat trick in some of my strategies.

however, be warned that changing an MA (or MA combination) can have a drastic effect on the meaning of the other parameters, and the 'gene-splicing' of these other parameters makes little sense (in biological terms it's like cross breeding completely different species). this reasults in making the optimization surface much more bumpy, and the optimizer is more likely to get stuck in a local maximum. you might find that different runs of the optimizer will give you completely different results. I'm thinking that some kind of covariance decomposition would help with this, but that's a whole different kettle of fish.

Reply With Quote
Thanked by:




Last Updated on December 16, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts