• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to detect optimization ?

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

    How to detect optimization ?

    How can be detected, that strategy runs in optimization mode?

    I would like to disable heavy writing to database and other not-needed functionality
    during optimization.

    #2
    While this is not currently documented, there is a StrategyBase.Category enum you can use to detect the mode it is running in. Since it's not documented, I cannot gurantee the behavior at this time, but do let us know if you see any issues

    Code:
    if (State == State.Configure)
    {
    	if (Category == Category.Backtest)
    		Print("Strategy is running a regular backtest ");
    	else if (Category == Category.Optimize)
    		Print("Strategy is running an optimization ");
    	else if (Category == Category.WalkForward)
    		Print("Strategy is running 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 an account from a chart/strategies tab ");
    }
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanx, it is completely clear now

      Comment


        #4
        Originally posted by NinjaTrader_Matthew View Post
        While this is not currently documented, there is a StrategyBase.Category enum you can use to detect the mode it is running in. Since it's not documented, I cannot gurantee the behavior at this time, but do let us know if you see any issues
        Is there, by the way, also such a undocumented feature for indicators? I'd like to check if my indicator is added to a chart or market analyzer; that way I can prevent drawing arrows in an environment that doesn't support it.

        I couldn't find it in the NT8 language reference.

        Comment


          #5
          Nothing as straight forward as the Category type, but here is something you can do. The indicator will either have a "Parent" or an "Owner" depending on how it's implemented. This is a quick way to test, but again since these are undocumented, this could change in a future release.

          Code:
          // check the type of window the chart is running on
          if (Owner is Chart)
          	Print("Running on a chart");
          
          else if (Owner is SuperDom)
          	Print("Running on a SuperDOM");
          
          // market analyzer indicator column is not the 'owner' window
          // therefore we needed to check against the 'parent' object type
          else if (Parent is MarketAnalyzerColumnBase)
          	Print("Running on a Market Analyzer");
          MatthewNinjaTrader Product Management

          Comment


            #6
            Originally posted by NinjaTrader_Matthew View Post
            While this is not currently documented, there is a StrategyBase.Category enum you can use to detect the mode it is running in. Since it's not documented, I cannot gurantee the behavior at this time, but do let us know if you see any issues

            Code:
            if (State == State.Configure)
            {
                if (Category == Category.Backtest)
                    Print("Strategy is running a regular backtest ");
                else if (Category == Category.Optimize)
                    Print("Strategy is running an optimization ");
                else if (Category == Category.WalkForward)
                    Print("Strategy is running 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 an account from a chart/strategies tab ");
            }
            If I may ask, what is the equivalent in NT7?

            Comment


              #7
              The equivalent would be BackTestMode, with three values: Backtest, Optimizer, or WalkForward.
              For example:
              Code:
              NinjaTrader.Strategy.BackTestMode.BackTest
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_PatrickH View Post
                The equivalent would be BackTestMode, with three values: Backtest, Optimizer, or WalkForward.
                For example:
                Code:
                NinjaTrader.Strategy.BackTestMode.BackTest
                Not quite. I remember trying that one before with useless results. It always returned "BackTest", as far as I remember.

                Just for grins and giggles, I tried it again anyway: I am often known to be wrong, after all. It was no different. Here we can clearly see that it is running on a chart, but it returns the same "BackTest", regardless of the connection.

                **NT** Enabling NinjaScript strategy 'StragegyRunningLocation/15e4a206a1b9494c8c789bf55381efc8' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes

                Strategy is running in Sim101
                Strategy account mode: Simulation
                Strategy connection: YAHOO
                Strategy mode: BackTest

                **NT** Disabling NinjaScript strategy 'StragegyRunningLocation/15e4a206a1b9494c8c789bf55381efc8'
                **NT** Enabling NinjaScript strategy 'StragegyRunningLocation/15e4a206a1b9494c8c789bf55381efc8' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes

                Strategy is running in Replay101
                Strategy account mode: Simulation
                Strategy connection: Market Replay Connection
                Strategy mode: BackTest
                Attached Files

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by spikeruk, Today, 01:49 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by Yandychang, Today, 02:16 PM
                5 responses
                17 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by priceisking, Today, 01:16 PM
                2 responses
                8 views
                0 likes
                Last Post priceisking  
                Started by kashyapjdave, 03-23-2017, 12:12 AM
                11 responses
                1,959 views
                0 likes
                Last Post forextrader2003  
                Started by Gav_G, 07-26-2018, 04:29 PM
                6 responses
                428 views
                0 likes
                Last Post forextrader2003  
                Working...
                X