NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > Application Technical Support > Strategy Analyzer

Strategy Analyzer Support for automated system backtesting and optimization using the NinjaTrader Strategy Analyzer.

Reply
 
Thread Tools Display Modes
Old 02-03-2009, 07:41 AM   #1
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
Default Bug with optimizer when changing parameter type

I changed one of my strategy parameters from int to double and then ran the strategy optimizer. For example I ran from 2;4;0.5 (2-4 stepping by 0.5). The results had the same values for 2 & 2.5, and the same for 3 & 3.5. It look me a while to figure it out but what was happening was the optimizer was using int instead of double.

I closed the strategy analyzer and then opened a new one and it worked properly.
cunparis is offline  
Reply With Quote
Old 02-03-2009, 07:47 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You were likely just still running on the old instance of your strategy with it being an int before.
NinjaTrader_Josh is offline  
Reply With Quote
Old 02-03-2009, 08:00 AM   #3
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
You were likely just still running on the old instance of your strategy with it being an int before.
Yes, that's what was happening but I consider that a bug. When I change the strategy the optimizer will use the new one, but apparently there is one change that doesn't get picked up and that's changing the parameter types. This makes sense because the strategy analyzer uses the parameters & parameter types to make the window.

I just thought I'd post it here in case you want to look into and/or if someone else notices weird behavior this could explain it. It took me a while to figure it out.
cunparis is offline  
Reply With Quote
Old 02-04-2009, 10:47 PM   #4
pureporsche
Junior Member
 
Join Date: Jan 2009
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Default

I have a similar problem... when changing a variable and backtest/optimize the parameter doesn't "save". I have a large formula with about 20 variables.

I've tried shutting the Strategy Analyzer (SA) down and starting it back up again and the values are still set as they were before the SA was closed. Changing them has no effect.

Even when I shut ninja trader down and start it back up I'm not be able to change the values. I have to go into the code, into the Variables and Properties to change the default values to be able to use them.

What may be the problem?
pureporsche is offline  
Reply With Quote
Old 02-05-2009, 01:36 AM   #5
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
Default

Quote:
Originally Posted by pureporsche View Post
I have a similar problem... when changing a variable and backtest/optimize the parameter doesn't "save". I have a large formula with about 20 variables.

I've tried shutting the Strategy Analyzer (SA) down and starting it back up again and the values are still set as they were before the SA was closed. Changing them has no effect.

Even when I shut ninja trader down and start it back up I'm not be able to change the values. I have to go into the code, into the Variables and Properties to change the default values to be able to use them.

What may be the problem?
I noticed something that could be similar I'm not sure. I have a variable "Optimize" that I set to 1 when running the optimizer and to 0 when not optimizing (backtest or running live). Sometimes when I run the optimizer with my Optimize set to 1;1;1, it doesn't optimize. I have to run the backtest with Optimize = 1 and then run the optimizer and it works.

There's something that I consider weird going on but apparently it's as designed. When you run a backtest or the optimizer, Ninjatrader will initialize your strategy more than once. I found this out because I print out the instrument name in my strategy. So let's say I run backtest on ES, I see my strategy print out both ES & QM. I have no idea why QM!

Could this be related?
cunparis is offline  
Reply With Quote
Old 02-05-2009, 07:16 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Initialize() is called at several points in time. You will get several prints.

As far as "saving" values go, the optimizer doesn't "save" parameter values. You have to change it away from what you coded as the default if this is something you wanted to do.

A 1;1;1 optimize doesn't optimize anything. This is why you may not see anything.
NinjaTrader_Josh is offline  
Reply With Quote
Old 02-05-2009, 08:03 AM   #7
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Initialize() is called at several points in time. You will get several prints.

As far as "saving" values go, the optimizer doesn't "save" parameter values. You have to change it away from what you coded as the default if this is something you wanted to do.

A 1;1;1 optimize doesn't optimize anything. This is why you may not see anything.
I'm not sure you understand. Optimize is my own variable. I use that to decide if I use my hardcoded values or the values supplied from the parameters.
cunparis is offline  
Reply With Quote
Old 02-05-2009, 08:09 AM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

If you run the optimizer on 1;1;1 it won't do anything. There is nothing to optimize.
NinjaTrader_Josh is offline  
Reply With Quote
Old 02-05-2009, 08:12 AM   #9
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
If you run the optimizer on 1;1;1 it won't do anything. There is nothing to optimize.
I have more parameters than just optimize.

like:

smaPeriod 10;20;5
optimize 1;1;1

if optimize = 1 it'll use the parameter values
if optimize = 0 it'll ignore the parameter values and use my hardcoded values

The reason I do this is because when I run live I want to be 100% sure I use the right parameters. So I hardcode them in the code.
cunparis is offline  
Reply With Quote
Old 02-05-2009, 08:16 AM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Then I am not sure what your concern is about.
NinjaTrader_Josh is offline  
Reply With Quote
Old 02-05-2009, 08:30 AM   #11
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Then I am not sure what your concern is about.
Because in my code I do something like this:

if(optimize==0) {
smaPeriod = myHardcodedSmaPeriod;
}

And sometimes when I put optimize=1, it still uses my hardcoded value. So I run backtest with optimize=1 and then rerun the optimizer (not changing anything) and then it works properly. The fact that initialize is invoked several times may have something to do with it, I'm not sure..
cunparis is offline  
Reply With Quote
Old 02-05-2009, 08:36 AM   #12
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Are you placing this code in Initialize()? Logic should NEVER be placed in Initialize().
NinjaTrader_Josh is offline  
Reply With Quote
Old 02-05-2009, 08:40 AM   #13
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Are you placing this code in Initialize()? Logic should NEVER be placed in Initialize().
No, it's in OnBarUpdate
cunparis is offline  
Reply With Quote
Old 02-05-2009, 08:43 AM   #14
pureporsche
Junior Member
 
Join Date: Jan 2009
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Default

Yes this is a similar issue I'm having.
When I say "save" I mean it doesn't hold the new new values when running the operation. It seems to be very erratic and hard to replicate - would be nice to give you a scenario.

I have double varA = -99.5 for instance in the code and then I change it (either in optimize or backtest) to -100 (I have 20 or so variables). When running it the value it uses is still -99.5.
If I close the strategy analyzer and reopen it, it makes no difference. I have to go into the code and change it.
pureporsche is offline  
Reply With Quote
Old 02-05-2009, 08:46 AM   #15
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

cunparis,

Just ensure you have a new instance of the strategy running.

pureporsche,

Not sure what you mean. You cannot change anything unless you have actually made it a parameter.
NinjaTrader_Josh 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
Optimizer Type: Max. Expectancy Elliott Wave NinjaScript File Sharing Discussion 7 05-01-2010 10:50 AM
New Optimizer Type: System Quality Number Pete S NinjaScript File Sharing Discussion 12 11-25-2009 10:04 PM
Indicator: Creating a user-defined parameter type (enum) NinjaTrader_Josh Reference Samples 0 09-24-2007 09:12 PM
Bug in Optimizer NinjaTrader_Josh Suggestions And Feedback 5 05-29-2007 02:02 AM
Problem with 'Parameter Type' set to Price codeye Miscellaneous Support 5 12-09-2005 07:06 AM


All times are GMT -6. The time now is 12:37 PM.