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 to tell Backtest and Optimization to go to next trading day

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

    How to tell Backtest and Optimization to go to next trading day

    I want to increase the speed of Optimization for my strategy. I have already done IsInstantiatedOnEachOptimizationIteration=false and coded my strategy to properly reset the variables. My strategy only trades during specific time of the day (e.g. between 9:30am to 12pm). Below is excerpt pseudo code of my strategy.


    Code:
    protected override void OnBarUpdate()
    {
    if(currentTime <= tradeStartTime || currentTime >= tradeStopTime){
    return;
    }
    else{
    // Do all the logic for trading strategy
    }
    
    }​
    Based on this pseudo code, during Backtest/Optimization, it is my understanding NT will go through every single bar available and if the bars fall within the given time range, then my trading strategy's logic will execute. How can I properly terminate my strategy if the time range is outside the desired trading time range and inform Backtest/Optimization to go to the next day. This way, we don't waste processor computation and memory on checking bars that are outside of the given time range?

    #2
    Hello wzgy0920,

    Thank you for your post.

    OnBarUpdate() will be called whenever a bar is updated. There is no way to tell OnBarUpdate() not to update at all on a certain condition. Your return statement however will ensure that it will skip any further calculation.

    Please let us know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello wzgy0920,

      Thank you for your post.

      OnBarUpdate() will be called whenever a bar is updated. There is no way to tell OnBarUpdate() not to update at all on a certain condition. Your return statement however will ensure that it will skip any further calculation.

      Please let us know if you have any further questions.
      Is it possible to request a feature to signal the Backtest/Optimization to terminate/skip the processing the strategy for the remaining bars of the trading session? As I mentioned I would like to Backtest/Optimize my strategy for specific time range of the trading session. During Bactest/Optimization NT is spending a lot of processing going through bars that doesn't actually result in strategy usage. This feature would help improve performance.

      Comment


        #4
        Hello,

        Thank you for the suggestion.

        I have submitted this as a feature request to the Development Team. I will follow up with an internal tracking number for your reference as soon as it is created.

        Thanks in advance for your patience.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          I would also very much like this feature to be implemented.
          I have a couple of specific time frames I want to create strategies for, that are between 10 minutes and half an hour.

          You would of course need to have the minimum bars needed before the start to have all indicator values used in the strategy correctly reflected etc.
          So I'm sure it's not trivial to implement.
          It seems that a big improvement can be made for strategies like these if you could specify a start and stop time for the optimization per day (where the strategy can take trades).

          Comment


            #6
            Is there a way to "terminate" a strategy from within the OnBarUpdate()? If so, what would happen in a case when IsInstantiatedOnEachOptimizationIteration=false​/?

            Comment


              #7
              Originally posted by bmggchevalier View Post
              I would also very much like this feature to be implemented.
              I have a couple of specific time frames I want to create strategies for, that are between 10 minutes and half an hour.

              You would of course need to have the minimum bars needed before the start to have all indicator values used in the strategy correctly reflected etc.
              So I'm sure it's not trivial to implement.
              It seems that a big improvement can be made for strategies like these if you could specify a start and stop time for the optimization per day (where the strategy can take trades).
              I want to bring your attention to two other related topics (see listed below). If you also are on the same boat as me, please provide your vote to NT dev team so they can increase the priority to improving the performance of Strategy Analyzer.

              I have questions and suggestions related Strategy Analyzer. 1) Currently the analysis of Optimization results is very very slow and painful. Please improve this. I run Optimization on multiple variables that span multiple weeks. The Optimization itself takes few hours, after which I am presented with top results. When I am

              I have few questions about using the Strategy Analyzer and some feedback for improvement. 1) How do I change the default strategy that appears when I go to New &gt;&gt; Strategy Analyzer &gt;&gt; General &gt;&gt; Strategy? Right it seems the list of strategies in the drop down box are alphabetically orders. Essentially I want

              Comment


                #8
                Hello bmggchevalier,

                I will add your vote to this feature request.
                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  Hello wzgy0920,

                  IsInstantiatedOnEachOptimizationIteration only determines if the strategy should be re-instantiated (re-created) after each optimization run when using the Optimizer.

                  https://ninjatrader.com/support/help...niteration.htm

                  The optimal approach to "terminate" a strategy from OnBarUpdate() is to use a return statement. You can also call CloseStrategy().

                  https://ninjatrader.com/support/help...sestrategy.htm


                  Please let me know if you have any other questions.
                  Gaby V.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Gaby View Post

                    The optimal approach to "terminate" a strategy from OnBarUpdate() is to use a return statement. You can also call CloseStrategy().
                    When I call CloseStrategy(), it does not stop the strategy. I checked that after I called CloseStrategy(), the OnBarUpdate() is still being called.

                    Comment


                      #11
                      Hello,

                      My apologies, I neglected to mention that CloseStrategy only works in real time. From the Help Guide page:

                      Warning: This method can only be call before the State has reached State.Terminated and after the State reaches State.Realtime

                      https://ninjatrader.com/support/help...sestrategy.htm


                      Instead of CloseStrategy(), you can use SetState(State.Terminated) to abort the strategy as it is running. Doing this in a Strategy Analyzer backtest will abort the backtest entirely, and no partial backtest results will be shown.

                      SetState() - https://ninjatrader.com/support/help...8/setstate.htm

                      Please let me know if you have any other questions.
                      Gaby V.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by wzgy0920 View Post

                        Is it possible to request a feature to signal the Backtest/Optimization to terminate/skip the processing the strategy for the remaining bars of the trading session? As I mentioned I would like to Backtest/Optimize my strategy for specific time range of the trading session. During Bactest/Optimization NT is spending a lot of processing going through bars that doesn't actually result in strategy usage. This feature would help improve performance.



                        This request is being tracked under the number SFT-6312.


                        As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted on the Release Notes page of the Help Guide.


                        Release Notes —https://ninjatrader.com/support/help...ease_notes.htm
                        Gaby V.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by burtoninlondon, Today, 12:38 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post burtoninlondon  
                        Started by AaronKoRn, Yesterday, 09:49 PM
                        0 responses
                        14 views
                        0 likes
                        Last Post AaronKoRn  
                        Started by carnitron, Yesterday, 08:42 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post carnitron  
                        Started by strategist007, Yesterday, 07:51 PM
                        0 responses
                        13 views
                        0 likes
                        Last Post strategist007  
                        Started by StockTrader88, 03-06-2021, 08:58 AM
                        44 responses
                        3,982 views
                        3 likes
                        Last Post jhudas88  
                        Working...
                        X