Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How can a strategy tell it is being optimized?

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

    How can a strategy tell it is being optimized?

    Dear NinjaTrader team,

    my strategy prints quite a bit of stuff to the Output Window, which is very useful for me during development. At the same time, I want to make sure that nothing is printed during optimization.

    Question: what is the recommended way for a strategy to tell if it was started by the optimizer?


    Thank you,
    best regards, Felix

    #2
    Originally posted by fbertram View Post
    Dear NinjaTrader team,

    my strategy prints quite a bit of stuff to the Output Window, which is very useful for me during development. At the same time, I want to make sure that nothing is printed during optimization.

    Question: what is the recommended way for a strategy to tell if it was started by the optimizer?


    Thank you,
    best regards, Felix
    I'd like to know that as well... I can figure out how to hide the bazillion parameters that I have in one of my strategies and make them available to the Strategy Analyzer, which I'd love to be able to do, if I knew the answer to that.

    Comment


      #3
      Hello fbertram,

      Thank you for your post.

      Utilizing the State.Historical in NinjaTrader 8 or the Historical bool in NinjaTrader 7 will allow you to determine if the strategy is running across historical data (backtesting) or if you are running over live/realtime data.
      However, this means if you wanted the Output when testing later you would need to edit your code again.

      So a solution would be to create your own bool that you set through the UI (User Defined Variable) to set whether or not you want the output or not. Then check for that bool before your Print() statements.

      Comment


        #4
        thank you Patrick, I can live with that workaround.

        As a low priority feature request, it would be great to have a way for the strategy to tell. Other tools have the GetAppInfo function, which gives the strategy access to quite a bit of useful information, which I have used in my strategies.

        Thank you,
        best regards, Felix

        Comment


          #5
          Interestingly I have just replied to similar question:

          There is a bool:
          IsInStrategyAnalyzer
          That may give you just what you want (but test it first)

          Comment


            #6
            Hi gregid,

            thanks a lot for your response. IsInStrategyAnalyzer is close... but unfortunately not enough. I'd like to be able to distinguish a standard backtest in Strategy Analyzer from an optimization, also in StrategyAnalyzer. As far as I can see, the bool you are suggesting will be true in both cases.

            Thanks again,
            Cheers, Felix

            Comment


              #7
              Originally posted by fbertram View Post
              Dear NinjaTrader team,

              my strategy prints quite a bit of stuff to the Output Window, which is very useful for me during development. At the same time, I want to make sure that nothing is printed during optimization.

              Question: what is the recommended way for a strategy to tell if it was started by the optimizer?
              In NT7,

              Code:
              if (Account.Name.Equals("Backtest"))
              {
                if (BackTestMode.ToString() == "Backtest")
                   Print("Normal backtest");
                else if (BackTestMode.ToString() == "Optimize")
                  Print("Optimiziing backtest");
              }
              else
                 Print("Running real-time - use Historical to know live or historical data");

              Comment


                #8
                excellent bltdavid, this seems to be just what I need. Do you have any hints for NT8?

                Comment


                  #9
                  Originally posted by fbertram View Post
                  excellent bltdavid, this seems to be just what I need. Do you have any hints for NT8?
                  Did you try it?

                  Sorry, not up to speed much with NT8.

                  Comment


                    #10
                    Yes, I tried. Unfortunately BackTestMode does not exist in NT8.

                    Thanks again,
                    Best regards, Felix

                    Comment


                      #11
                      Originally posted by fbertram View Post
                      Yes, I tried. Unfortunately BackTestMode does not exist in NT8.

                      Thanks again,
                      Best regards, Felix
                      In NT8, there is the undocumented StrategyBase.Category enum. Remember that it is not documented, so it can very well cease to work. Be advised accordingly.
                      Code:
                      if (State == State.Configure)
                      {
                      	if (Category == Category.Backtest)
                      		Print("Strategy is running a backtest ");
                      	else if (Category == Category.Optimize)
                      		Print("Strategy is running an optimization ");
                      	else if (Category == Category.WalkForward)
                      		Print("Strategy is running a Walk-Forward optimization");
                      	else if (Category == Category.MultiObjective)
                      		Print("Strategy is running a multi objective optimization ");
                      	else if (Category == Category.NinjaScript)
                      		Print("Strategy is running on a chart/strategies tab ");
                      }
                      I believe that this has been disclosed on this forum before, but I could not find the original post to reference.
                      Last edited by koganam; 10-31-2016, 09:08 AM.

                      Comment


                        #12
                        awesome, exactly what I was looking for!

                        Thanks a lot,
                        Best regards, Felix

                        Comment


                          #13
                          Thanks a lot, koganam
                          fx.practic
                          NinjaTrader Ecosystem Vendor - fx.practic

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by funk10101, Today, 09:43 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post funk10101  
                          Started by pkefal, 04-11-2024, 07:39 AM
                          11 responses
                          36 views
                          0 likes
                          Last Post jeronymite  
                          Started by bill2023, Yesterday, 08:51 AM
                          8 responses
                          44 views
                          0 likes
                          Last Post bill2023  
                          Started by yertle, Today, 08:38 AM
                          6 responses
                          25 views
                          0 likes
                          Last Post ryjoga
                          by ryjoga
                           
                          Started by algospoke, Yesterday, 06:40 PM
                          2 responses
                          24 views
                          0 likes
                          Last Post algospoke  
                          Working...
                          X