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

              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 samish18, Yesterday, 08:57 AM
                8 responses
                25 views
                0 likes
                Last Post samish18  
                Started by DJ888, 04-16-2024, 06:09 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by RookieTrader, Today, 07:41 AM
                0 responses
                3 views
                0 likes
                Last Post RookieTrader  
                Started by maybeimnotrader, Yesterday, 05:46 PM
                1 response
                18 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Perr0Grande, Yesterday, 08:16 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X