Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bug with optimizer when changing parameter type

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    #2
    You were likely just still running on the old instance of your strategy with it being an int before.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      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.

      Comment


        #4
        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


          #5
          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?

          Comment


            #6
            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


              #7
              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.

              Comment


                #8
                If you run the optimizer on 1;1;1 it won't do anything. There is nothing to optimize.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  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.

                  Comment


                    #10
                    Then I am not sure what your concern is about.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      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..

                      Comment


                        #12
                        Are you placing this code in Initialize()? Logic should NEVER be placed in Initialize().
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          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

                          Comment


                            #14
                            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


                              #15
                              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.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RubenCazorla, 08-30-2022, 06:36 AM
                              3 responses
                              77 views
                              0 likes
                              Last Post PaulMohn  
                              Started by f.saeidi, Yesterday, 12:14 PM
                              9 responses
                              23 views
                              0 likes
                              Last Post f.saeidi  
                              Started by Tim-c, Today, 03:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Tim-c
                              by Tim-c
                               
                              Started by FrancisMorro, Today, 03:24 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post FrancisMorro  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,772 views
                              0 likes
                              Last Post Leafcutter  
                              Working...
                              X