Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit on Close Question

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

    Exit on Close Question

    Hello-

    I thought I was very familiar with the ExitOnClose usage but I'm not getting the results I desire. Please note that this is for an unmanaged approach.

    In backtesting, Exit on Close (in the Strategy Analyzer) is set to true. The strategy will successfully exit on close in backtesting, though not quite as expected. I use "ExitOnCloseSeconds = 3600" because I want the strategy to close at 4PM instead of 5PM (this is based on the session template for the instrument in question, and all of these are CME Globex products. I have not changed the defaults for CME FX Futures ETH). In backtesting, the strategy exits at the end of the session's defined time (5PM EST), not 4PM EST as instructed. I've learned recently that ExitOnClose doesn't work for backtesting, which is fine.

    When running the strategy live, however, the strategy will not close at 4PM EST as instructed.

    Am I missing something in this case? I have "ExitOnClose = True" within Initialize(). Here is a copy of the initialization code:

    Code:
    protected override void Initialize()
            {
    			try
    			{
    				// Bar on close?
    				CalculateOnBarClose = true;
    				
    				// Account Size
    				localPnL = GetAccountValue(AccountItem.RealizedProfitLoss);
    				
    				// Suppress messages for now.
    				TraceOrders = true;
    				SyncAccountPosition = false;
    				Unmanaged = true;
    				IncludeCommission = true;
        			        IgnoreOverFill = false;
    
    				// Error handling:
    				RealtimeErrorHandling = handleErrors ? 
    					RealtimeErrorHandling.StopStrategyCancelOrdersClosePositions 
    					: RealtimeErrorHandling.TakeNoAction;
    				
    				// Exit any position 60 minutes before the close;
    				ExitOnClose = true;
    				ExitOnCloseSeconds = 3600;
    				SyncAccountPosition = false;
    				
    				// Maximum bar lookback
    				MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    
    				// Add any indicators to the chart here
    				Add(SMA(movingAveragePeriod));
    			}
    			
    			catch (Exception ex)
    			{
    				if (debugOutput)
    				{
    					DebugMessage(BarsInProgress, CurrentBar, Instrument, "Exception caught Initialize(): " + ex);
    				}
    			}
    		}
    Ultimately, can't figure out why ExitOnClose isn't hitting. Strategy works flawlessly otherwise and has been fairly extensively tested.

    I should note that I'm using a 10 min delayed feed from DTN for "live" testing - would this cause issues?
    Last edited by cgeorgan; 06-20-2016, 02:43 PM.

    #2
    Hello cgeorgan,

    Thank you for your post.

    With CalculateOnBarClose set to true the strategy will not calculate until the close of a bar. If that close is not exactly 3600 seconds before the session end it will not work.
    What is the base/primary series for the bars used for the strategy? Such as the bar series on the chart you apply the strategy to.

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello cgeorgan,

      Thank you for your post.

      With CalculateOnBarClose set to true the strategy will not calculate until the close of a bar. If that close is not exactly 3600 seconds before the session end it will not work.
      What is the base/primary series for the bars used for the strategy? Such as the bar series on the chart you apply the strategy to.
      Patrick,

      I only use one primary series per strategy instance. However, they are all tick-based (none are time based). Based on what you've said, it sounds like I won't hit my close.

      Would some logic that simply asks if the time of this bar is after the end of the session template ? close : don't close work?

      Comment


        #4
        Originally posted by cgeorgan View Post
        Would some logic that simply asks if the time of this bar is after the end of the session template ? close : don't close work?
        Yes, you could use a check of the time in order to close positions. For example:
        Code:
        if (ToTime(Time[0]) >= 160000)
        {
        ExitLong();
        ExitShort();
        }

        Comment


          #5
          If tick or sec based time periods are used would setting the sec prior to close at a long enough time period prior to close such that you would be assured of at least one bar formation work? Sorry for the run on sentence.

          GuppyDRV

          Comment


            #6
            Patric,

            Can you explain more as to why this function will not back test? I know in the help guid it states it is a live function only. If using OBC and the time is far enough prior to close to ensure a bar prior to close?

            My first thought when I started down this road is that this function is not dependent OBC but simply a time induced close regardless of where the bar formation process is presently.

            I have created a custom template to trade Sun 17:00 central until Fri 15:15 central with computer time set to Central. Using the 24/5 or 24/7 template with exit on close I get vastly different results from my custom template. The 24/5 24/7 forces closes at some really strange times that I'm not able to afix with any known times. My custom comes closer to closing when needed. Additionally, how are early closes or holiday closes accounted for as NT7 doesn't seem to have these nested internally. Would some screen shots of the strange times etc.... Help. Does NT 8 work any differently with these issues? Is there a way to get a more accurate back test when using exit on close?

            Thanks for the help.

            GuppyDRV

            Comment


              #7
              Originally posted by GuppyDRV View Post
              If tick or sec based time periods are used would setting the sec prior to close at a long enough time period prior to close such that you would be assured of at least one bar formation work? Sorry for the run on sentence.

              GuppyDRV
              You would want to give at least two bars in a time based scenario to ensure the next bar can process the exit request.

              Comment


                #8
                Originally posted by GuppyDRV View Post
                Can you explain more as to why this function will not back test? I know in the help guid it states it is a live function only. If using OBC and the time is far enough prior to close to ensure a bar prior to close?

                ...

                Would some screen shots of the strange times etc.... Help. Does NT 8 work any differently with these issues? Is there a way to get a more accurate back test when using exit on close?
                I am not sure which function you refer to that will not backtest.

                Screenshots of what you are explaining would be most helpful.
                NinjaTrader 8 does account for holidays in the trading hours templates: http://ninjatrader.com/support/helpG...ding_hours.htm

                Comment


                  #9
                  Patrick,

                  Thanks was referencing the exit on close function and how to get this to more accurately back test. How do other people deal with holiday or short trading sessions in NT7?

                  GuppyDRv

                  Comment


                    #10
                    Hello GuppyDRV,

                    ExitOnClose will backtest as long the ExitOnCloseSeconds is hit by a bar before the last bar of the chart. Otherwise the exit occurs on the first bar of the session.

                    Comment


                      #11
                      Patrick,
                      I'm having a similar issue with exitonclose. Using the unmanaged approach as well with Adaptrade builder strategies in NT 7. I'm trying to ExitOnClose 4500 seconds before the close with the ES. CalculateOnBarClose = false. Sometimes the exit on close function is filled in demo and other times it just completely runs through the close with an open position. Not using time based bars and using the standard managed order code that comes with their software. Any ideas as to what is happening here? Thanks.

                      Comment


                        #12
                        Patric,

                        Where would I set this exit time for backtest or WFO I'm not seeing a setting on either of these (only a choice to exit on close no spot to set time). I do see a setting on the strategy window when attaching a strategy to a chart. Is this somehow connected.

                        Has NT8 addressed or improved upon any of these issues?

                        GuppyDRV

                        Comment


                          #13
                          Hello dirkdiggler,

                          Thank you for your post.

                          If the tick bars are not closing exactly at or after the session close time minus the ExitOnCloseSeconds then you will not see the exit occur.

                          I would recommend performing the check as described at the following link or using a larger value for ExitOnCloseSeconds.

                          Comment


                            #14
                            GuppyDRV,

                            ExitOnCloseSeconds would be set in code: http://ninjatrader.com/support/helpG...oseseconds.htm

                            Comment


                              #15
                              I would like to clarify this matter for all on this thread and anyone visiting this thread.

                              The cause of this is due to the Historical bars always processing as CalculateOnBarClose = true. This means the open, high, low, and close of the bar is known only at the close time of the bar.
                              If you run a strategy with ExitOnCloseSeconds then the bars that closes before the last bar close at session close must close on or after the session close time minus the ExitOnCloseSeconds.

                              In NinjaTrader 8, you can use Tick Replay when running backtests over Historical data, which means you can use the calculate method of OnPriceChange historically. For more information please visit the following link: http://ninjatrader.com/support/helpG...ick_replay.htm

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by halgo_boulder, 04-20-2024, 08:44 AM
                              2 responses
                              21 views
                              0 likes
                              Last Post halgo_boulder  
                              Started by mishhh, 05-25-2010, 08:54 AM
                              19 responses
                              6,189 views
                              0 likes
                              Last Post rene69851  
                              Started by gwenael, Today, 09:29 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post gwenael
                              by gwenael
                               
                              Started by Karado58, 11-26-2012, 02:57 PM
                              8 responses
                              14,830 views
                              0 likes
                              Last Post Option Whisperer  
                              Started by Option Whisperer, Today, 09:05 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Option Whisperer  
                              Working...
                              X