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

Exit on Session Close with Line Break Bars

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

    Exit on Session Close with Line Break Bars

    Hello there NT community,


    •On historical data, IsExitOnSessionCloseStrategy will cause positions to be exited at the close of the last bar of the session
    Can the above behaviour be reproduced to happen in real time?

    Click image for larger version

Name:	Capture3breakhist.PNG
Views:	212
Size:	8.4 KB
ID:	1115103Click image for larger version

Name:	Capturedata.PNG
Views:	178
Size:	14.4 KB
ID:	1115104
    ​​​
    Above screenshot to the left is a strategy applied to historical data. Data Series to the right.( Symbol is BTC USD )
    The Strategy's Order Fill Resolution is set to high (ticks). Calculate: On bar close




    Market replay however does close later (as intended), 30 secs prior to the session's end.





    The way Exit on session close happens during backtests using Line Break Bars, will often cause positions to be closed at convenient points in time, as seen in the first screenshot.
    Results were significantly better with various different session templates compared to having Exit on session close disabled.
    Last edited by youdee101; 08-22-2020, 07:13 PM.

    #2
    Hello youdee101,

    In backtest the Exit on close always occurs at the end of the bar. This is a limitations of the Exit on close with backtesting. (You can add intra-bar granularity and use logic to exit a position at a specific time historically before the last bar of the session closes)
    https://ninjatrader.com/support/foru...377#post773377

    Are you asking how to submit an order after the session has closed in real-time? (After the session has closed some brokers will no longer accept orders to exit a position)

    This example may give you some ideas on how to work with the exit on close.
    https://ninjatrader.com/support/foru...ose#post100666
    Last edited by NinjaTrader_ChelseaB; 08-23-2020, 11:14 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      What I wonder is if there is some sort of lookahead bias happening during backtests.
      Backtested the end of session is 9PM.
      Market Replay was at 2 AM.

      The end of session should be at midnight. +2 hours for my timezone would make sense for it to be 2AM.

      Is really hope this is not a bug.

      Comment


        #4
        Hello youdee101,

        What Trading hours template is selected for the backtest?

        What is your time zone?

        Are you looking at the last exit on close or previous ones and the previous ones all also end the session at 9?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          the template is Cryptocurrency, timezone is CET.
          Click image for larger version

Name:	exittimes.PNG
Views:	176
Size:	48.6 KB
ID:	1115274

          even though exit and entry should be at midnight +1 or +2 hours if daylight saving time applies.

          Having exits at 3 or 4 PM made me wonder.

          Thanks for your quick reply btw.

          Comment


            #6
            Hello youdee101,

            I would be expecting the exit on session close to be at the same time each day when using the Cryptocurrency trading hours template.

            Testing on my end with BCHEUR confirms this, attached is a screenshot showing the parameters of the backtest.

            Where is the Trading hours break line showing on the chart?

            Is the historical data complete data or does this have gaps?

            Has the Cryptocurrency trading hours template been modified?
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Data Looks like this and I was able to reproduce your backtest with 1 min candles. Template not tampered with.

              Click image for larger version  Name:	Capturebreak line data.PNG Views:	0 Size:	32.3 KB ID:	1115289
              However I am concerned with 60 minute Line Break.

              Click image for larger version  Name:	Capturebtceurlb.PNG Views:	0 Size:	140.2 KB ID:	1115288
              Last edited by youdee101; 08-24-2020, 09:05 AM.

              Comment


                #8
                Hello youdee101,

                It looks like with 60 minute line break bars the last bar of the session closes at a different time as there isn't enough movement to make more bars that close closer to the end of the session.

                The trading hours break line appears to be in the correct place and the exit on session close orders are happening where the trading hours break line is.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  It looks like with 60 minute line break bars the last bar of the session closes at a different time as there isn't enough movement to make more bars that close closer to the end of the session.
                  How would I go about recreating this "closing of positions prematurely" , before the actual session close when running the strategy live.

                  As shown in my first post. Backtest close = 9PM , Market Replay close = 1:59:31PM (30 seconds prior to session end).

                  Comment


                    #10
                    Hello youdee101,

                    There wasnt enough movement in that session to make more bars after that bar. So that bar became the last bar of that session.

                    Are you certain you want to be using line break bars. This is how they work and are based on movement. If there is not enough movement no more bars get made.
                    https://ninjatrader.com/support/help...gLineBreakBars

                    As a heads up, Line break bars cannot use TickReplay to build accurately in historical data as in real-time this bar type modifies its open.
                    "Notes: 5.Due to the nature of how some unique bars build, Tick Replay is NOT available for all bar types. For example, the default Renko and LineBreak bars which use RemoveLastBar() are not compatible with Tick Replay. Other custom bar types which use similar methods encounter the same limitation"
                    https://ninjatrader.com/support/help...ick_replay.htm


                    In real-time I would expect the exit on session close to occur at the number of seconds before the session closes that is specified.

                    Are you able to reproduce this using the playback and show that the exit on close is occurring in real-time at a number of seconds before what is specified?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Are you able to reproduce this using the playback and show that the exit on close is occurring in real-time at a number of seconds before what is specified?
                      Market Replay achieved this.

                      // Add a Tickdata Series to execute trades on
                      AddDataSeries(Data.BarsPeriodType.Tick, 1); // BarsArray[1]


                      I used this tick series to execute signals from the linebreak chart on.
                      So with the modifying opens, this means that only market replay or real time would give me accurate fill prices?

                      Comment


                        #12
                        Hello youdee101,

                        Adding a 1 tick series and placing orders to the 1 tick series would increase the accuracy of fill prices.


                        (This would not affect the exit on close which occurs on the primary series)
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Haiasi, Today, 06:53 PM
                        1 response
                        4 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by ScottWalsh, Today, 06:52 PM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by ScottW, Today, 06:09 PM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by ftsc2022, 10-25-2022, 12:03 PM
                        5 responses
                        256 views
                        0 likes
                        Last Post KeyonMatthews  
                        Started by Board game geek, 10-29-2023, 12:00 PM
                        14 responses
                        244 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Working...
                        X