Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"exit on session close" not working as expected in strategy analyzer

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

    "exit on session close" not working as expected in strategy analyzer

    I'm backtesting a strategy that I've built in the strategy builder. I'm trying to set up my strategy to flatten all of my positions at 3:14pm CST. However, when I run the backtest and check the 30-minute analysis for "exit time", the results indicate a lot of trade exits after 3:30pm and 4:30pm CST. I'd appreciate some help to figure out why my strategy is exiting many trades after 3:14pm in backtesting.

    In the strategy default settings, I've selected "exit on session close". The "exit to session close seconds" are set to 2760. The instrument is ES, so I believe this should equal 3:14pm CST. "time in force" is set to "day". In the strategy backtest settings, I've also selected "exit on session close" and "time in force" is set to "day".

    My strategy conditions have a timeframe restriction to only allow trades between 8:00am and 3:10pm CST. This is working properly, so the strategy doesn't enter trades after 3:10PM. I've also created a trading hours template for the ES, setting each day's session to end at 4:00PM CST, with the EOD set to true for each session. However, this doesn't change the behavior of exiting trades after 3:30PM and 4:30PM in backtests.
    Last edited by tradykat; 05-25-2020, 09:51 PM.

    #2
    Hello tradykat,

    Thank you for your note.

    ExitOnSessionCloseSeconds is a real-time only property, it will not have any effect on your ExitOnSessionClose time in backtesting when processing historical data.

    On historical data, such as in the Strategy Analyzer, IsExitOnSessionCloseStrategy will cause positions to be exited at the close of the last bar of the session. If you are using a non time-based Bar Type, such as Renko, and have "Break at EOD" set to False on the Data Series, this means that IsExitOnSessionCloseStrategy could trigger after the session close, since the last bar of the session can extend beyond the session close time in this scenario.

    Even if you're backtesting with a historical order fill resolution set to be more granular than your base primary series, the ExitOnSessionCloseSeconds will still be tied to the primary higher timeframe series bar.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the info, Kate. I'm not familiar with the IsExitOnSessionCloseStrategy. Can IsExitOnSessionCloseStrategy function be accessed through the Strategy Builder, or do I need to manually edit code? I don't know to edit code yet. I'm using tick based historical data in my strategy (ie, 1500 tick bars). Is it possible to exit at (or before) session close while using tick based bars in the historical data series? Can I choose what time the session close occurs, for example with a trading hours template?

      Comment


        #4
        Do trading hours templates over-ride the trading timeframes specified in strategy conditions? After more experimenting with backtesting my strategy with a custom trading hours template, my strategy enters trades based upon the hours of the custom trading hours template, versus the trading timeframes I've specified in the strategy conditions. If I set the trading hours in the strategy analyzer to the default instrument trading hours, then my strategy enters trades according to the timeframes I've specified in the strategy conditions.

        Comment


          #5
          Also, my backtest results using "break at EOD" are puzzling as well. As I understand it, strategies based on tick based bars should set "break at EOD" to false in order to allow the last bar to complete before exiting the session. However, my tick based bar strategy is significantly more profitable in backtesting when "break at EOD" is set to true. Does this simply indicate that my strategy usually takes large losses on the last bar of the session if it is allowed to complete printing?

          Comment


            #6
            Hello tradykat,

            Thank you for your replies.

            In the Strategy Builder, IsExitOnSessionCloseStrategy is controlled by the Exit on Close checkbox on the Default Properties screen - you will need to expand the More Properties section to see it.

            Trading hours templates would only override the strategy from taking trades outside the trading hours specified. For example, if you were using US Index Futures RTH hours, but have time filters in your strategy to take trades between, say 9 pm and 4 am, you wouldn't see any trades listed as the strategy isn't allowed to take trades during those hours. If you're not seeing it take trades when it should be allowed to during the specified trading hours, the first thing I would advise would be to turn on the Trace Orders function:

            Strategy Builder > Default Properties > More Properties > Trace Orders, or in code:

            if (State == State.SetDefaults)
            {
            TraceOrders = true;
            }

            Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

            Here is a link to our help guide that goes into more detail on tracing orders:


            Trace orders alone may not give you the full picture of whether or not a trade should have been entered on a given bar, so adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful.

            This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.



            If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess what is different between the two.

            As far as Break at EOD goes, the importance of it with Tick based bars is that you have a constant, reproducible start time for the day each day. With tick bars, even a single tick difference between bars can create a very different chart, so I would expect there to be major differences in PnL between the two settings with tick based bars.

            Please let us know if we may be of further assistance to you.

            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Thank you very much for your detailed reply, Kate.

              At the moment, I just need some clarification on your statement - "As far as Break at EOD goes, the importance of it with Tick based bars is that you have a constant, reproducible start time for the day each day." I've reviewed the explanation of Break at EOD here: https://ninjatrader.com/support/help...eak_at_eod.htm
              I think I understand the effect of Break at EOD on the final bar of the session, however I can't understand how this affects the start time for the next day's session. What am I missing with this concept?

              Comment


                #8
                Hi tradykat,
                Here is an earlier post of mine in this respect for time based bars ...
                https://ninjatrader.com/support/foru...-in-a-strategy
                The issue with tick based bars is exactly the same, if you don't use Break at EOD. Assume, you want 1000 ticks for a candle.
                Can you tell at which time the first candle of the next day will start to form? NO. Why?
                If your last candle of the preceding day only has 250 ticks before the session was over, the first 750 ticks on the next day are still needed to fill up the last candle which started forming on the day before. Only then, the first candle of the next day starts to form.
                Now, since the number of ticks in the last candle of the day will always be different (one day 999 / 1, next day 137 / 823, next day 5 / 995) , your issue on the next day is even worse than it is in my time based example. With ticks, you never know when your first tick based bar starts to form on the next day, unless you break at EoD, means the last tick candle on your chart for a given day will NOT include 1000 ticks (other than by pure coincidence once in a lifetime).
                NT-Roland
                Last edited by NT-Roland; 05-26-2020, 04:38 PM.

                Comment


                  #9
                  Thank you for that additional help, NT-Roland. That does clarify the concept for me. As I've thought about it further, I suppose in my case it's simply a matter of choosing the Break at EOD option that gets the best backtest results with my strategy.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ghoul, Today, 06:02 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post ghoul
                  by ghoul
                   
                  Started by Barry Milan, Yesterday, 10:35 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post Barry Milan  
                  Started by DanielSanMartin, Yesterday, 02:37 PM
                  2 responses
                  13 views
                  0 likes
                  Last Post DanielSanMartin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  4 responses
                  13 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by terofs, Today, 04:18 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post terofs
                  by terofs
                   
                  Working...
                  X