I closed the strategy analyzer and then opened a new one and it worked properly.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Bug with optimizer when changing parameter type
Collapse
X
-
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.Tags: None
-
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.Originally posted by NinjaTrader_Josh View PostYou were likely just still running on the old instance of your strategy with it being an int before.
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.
Comment
-
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?
Comment
-
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.Originally posted by pureporsche View PostI 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?
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?
Comment
-
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.Josh P.NinjaTrader Customer Service
Comment
-
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.Originally posted by NinjaTrader_Josh View PostInitialize() 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.
Comment
-
I have more parameters than just optimize.Originally posted by NinjaTrader_Josh View PostIf you run the optimizer on 1;1;1 it won't do anything. There is nothing to 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.
Comment
-
Because in my code I do something like this:Originally posted by NinjaTrader_Josh View PostThen I am not sure what your concern is about.
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..
Comment
-
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.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
111 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
59 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
38 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
41 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
78 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment