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

  #41 (permalink)
 
caprica's Avatar
 caprica 
USA
 
Experience: Master
Platform: NinjaTrader
Posts: 155 since Jul 2009
Thanks Given: 45
Thanks Received: 114


piersh View Post
unfortunately not, there's no way for the optimizer to get access to the underlying performance data required to do this.

my suggestion is that you build this rule into your scoring function. either as a weight, (eg. multiply your score by the net profit), or as a cut-off (eg. return double.NegativeInfinity for all scores with avg daily net profit less than a certain value).

Thanks, I am currently using the * netprofit method but it has a lot of drawbacks. I'll try the double.NegativeInfinity advice. I will see if I can modify your popup dialog window to include a minimum threshold to pass to the optimizer for this variable.

"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
Futures True Range Report
The Elite Circle
 
  #42 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120


baruchs View Post
Piersh hi,
Great staf.
I have a question. Maybe you can help.
Its about Walk Forward. The sequence now in NT is:
Load min. bars required>optimize(Optimization period - min. bars required)>Load min. bars required>Test(Test period - min. bars required)> New Optimization (From date + Test period) etc.
My problem is that if Test Period is 7 days and min. bars required are 100 on a 10 min. time frame and a day session (8:30-15:15), this mean that 2 days are not tested.
Is there a way to move the "From Date" back on each iteration to achieve the correct sequence:
optimize(Optimization period)>Test(Test period)>New optimize.

Regards,
Baruch

sorry, i'm not too familiar with the details of walk forward. you might find more useful answers in a more general forum - it doesn't sound like your issue is directly connected with the optimizer, but NT's walk forward function (of which the optimizer is a small part). do you see the same problem using NT's built-in optimizer?

Reply With Quote
  #43 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009


Yes in default optimizer its the same.
I all ready asked the NT support but all they could say is that they will forward it to the development. I don't count on a solution from them.
The problem exists in optimizer also, but in optimizer I added my own "trade from date" and in NT "From" I enter a smaller date.
As I see it the strongest tool in NT is the Walk Farward, because the optimizer optimizes on a given data and only if you test it on next data sample the strategy is valid.

Thanks,
Baruch

Reply With Quote
  #44 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10

Thank you piersh! I have used it to change my stop loss ticks and trail stops. Appreciate it!

Reply With Quote
  #45 (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,397 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537

Hi piersh,

I'm using v1.06 but on one particular strategy am getting an error. I've used your GO successfully on several strategies, this is the first I've seen this.

Failed to call method 'Optimize' for optimizer 'PHGenetic'. Unable to cast object of type 'System.Double' to type 'System.String'.

It works fine with the normal optimizer.

My guess is it is trying to Print() something when the error occurs. I am making this assumption because I receive your pop-up Window with options, and as soon as I press OK the error appears -- before your header statement is printed to the Output window.

Sorry I can't include the strategy for you to test against. Any ideas where to begin? I will try looking through your code and commenting out some Print() statements to see if my theory is right, but I guess it could easily be something else. Not sure why you would be converting something to a string elsewhere though.

-- Edit. Hmm ok you have overriden the ToString() function and it seems do a lot of custom work using ToString. So... hopefully you have any idea how to fix this, maybe you can send a test version with more debug output.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #46 (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,397 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537

Well I see you already wrapped Optimize() in a try/catch so I enabled the Catch and printed the exception:

 
Code
                            
System.InvalidCastExceptionUnable to cast object of type 'System.Double' to type 'System.String'.
   
at NinjaTrader.Strategy.Parameter.set_Value(Object value)
   
at NinjaTrader.Strategy.IntegralParameterDefinition.WriteValue(StrategyBase strategyInt32 iValue)
   
at NinjaTrader.Strategy.PHGenetic.ScoreGeneration(IEnumerable`1 rgChildren)
   at NinjaTrader.Strategy.PHGenetic.Optimize() 
I will check further but your help is appreciated.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #47 (permalink)
 
sefstrat's Avatar
 sefstrat 
Austin, TX
 
Experience: Advanced
Platform: NT/Matlab
Broker: Interactive Brokers
Trading: FX majors
Posts: 285 since Jun 2009
Thanks Given: 20
Thanks Received: 768

Hey Mike, I've run into a similar problem before and was trying to remember what caused it.. iirc it was something like this:

Print("string " + intVar + 5);

Technically this is valid c#, but for some reason the JIT compiler NT is using has trouble with it (they use modified JIT engine for remotesoft protector). It is especially annoying because their replacement hooks the MS JIT compiler with unmanaged code, so you cannot debug such problems with visual studio..

I found that changing it to this made it work:

Print("string " + (intVar+5).ToString());

Not sure if that is the problem in your case but worth a shot.

Reply With Quote
  #48 (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,397 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537

thx sefstrat, I have run into that before. But that is not the issue here as best I can tell. If you take a look at PHgenetic.cs from post 1 I think you'll see why.

Hopefully piersh can help.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #49 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120


Big Mike View Post
Well I see you already wrapped Optimize() in a try/catch so I enabled the Catch and printed the exception:

 
Code
                            
System.InvalidCastExceptionUnable to cast object of type 'System.Double' to type 'System.String'.

   
at NinjaTrader.Strategy.Parameter.set_Value(Object value)
   
at NinjaTrader.Strategy.IntegralParameterDefinition.WriteValue(StrategyBase strategyInt32 iValue)
   
at NinjaTrader.Strategy.PHGenetic.ScoreGeneration(IEnumerable`1 rgChildren)
   at NinjaTrader.Strategy.PHGenetic.Optimize() 
I will check further but your help is appreciated.

Mike

try changing the lines (line ~1007)

 
Code
else
{
	_rgParameterDefinitions.Add (new IntegralParameterDefinition (Strategy, iParam));
}
to

 
Code
else if (type.IsPrimitive)
{
	_rgParameterDefinitions.Add (new IntegralParameterDefinition (Strategy, iParam));
}

Reply With Quote
Thanked by:
  #50 (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,397 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537



piersh View Post
try changing the lines (line ~1007)

 
Code
else
{
    _rgParameterDefinitions.Add (new IntegralParameterDefinition (Strategy, iParam));
}
to

 
Code
else if (type.IsPrimitive)
{
    _rgParameterDefinitions.Add (new IntegralParameterDefinition (Strategy, iParam));
}

Thank you, that seems to have corrected it.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




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