• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit on close

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

    Exit on close

    NinjaTrader Community,

    A common inquiry is that the Exit on close didn't work in a NinjaScript Strategy because there is a position after the exit on close should have occurred.

    When viewing the log we often find that the Exit on close does indeed exit the position shortly before the end of the session (based on the Exit on close seconds), however, after the exit the strategy places a new order and re-enters the position.

    The Exit on close trigger will not prevent a NinjaScript Strategy from placing new orders after this has triggered and this can cause your strategy to take a new position before the end of the session (causing a position to be left open when the session is closed).

    I've created a video to demonstrate that first, the Exit on close does work, and second that a new position will be created if the script allows for it. Last, I demonstrate a script that uses a Session Iterator and the Exit on close seconds to set a flag that prevents trades after the exit on close until the new session has started.

    https://www.screencast.com/t/PwQNUU7f1

    Attached is the PreventEntryAfterExitOnCloseExample tested in the video.
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 10-11-2017, 01:00 PM.
    Chelsea B.NinjaTrader Customer Service

    #2
    is there a difference to adding all that script and making a session iteration rather than just adding a check for currentbars[0] != bars.isfirstbarofsession into your script.

    all else equal and granted that we are using calculate on bar close. it feels like it would produce the same result with a lot less clutter?

    Comment


      #3
      Hello travelingsalesman,

      Thank you for your note.

      You could prevent a strategy from taking a trade after exit on close was called many different ways.

      Resetting a variable which prevents trades being taken after ExitOnClose using Bars.IsFirstBarOfSession would work too. An example of resetting a variable on first bar of session can be found here,
      https://ninjatrader.com/support/foru...ad.php?t=19182

      You could also use a time filter. An example of using a time filter can be found below,
      https://ninjatrader.com/support/foru...ead.php?t=3226

      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        awesome thanks for that info

        Comment


          #5
          just wanted to follow up for anybody else who might stumble upon this thread i was able to fix my problem just by adding this line of code to the beginning of the script BEFORE the actual trading logic.

          if (Bars.IsFirstBarOfSession || Bars.IsLastBarOfSession)
          return;

          this prevents any trades to be entered at the last bar of a session or first bar of a session. for me my problem was the last bar of the session was triggering trades

          hope this helps someone.

          Comment


            #6
            Originally posted by travelingsalesman View Post
            just wanted to follow up for anybody else who might stumble upon this thread i was able to fix my problem just by adding this line of code to the beginning of the script BEFORE the actual trading logic.

            if (Bars.IsFirstBarOfSession || Bars.IsLastBarOfSession)
            return;

            this prevents any trades to be entered at the last bar of a session or first bar of a session. for me my problem was the last bar of the session was triggering trades

            hope this helps someone.
            Thanks for sharing. I assume this will work only for Time based bars. Tick based bars won't work. Can anyone confirm?

            Comment


              #7
              Hi roblogic, thanks for your post.

              Those two properties will still work with tick based charts. I tested with the playback connection and received a session begin and end on 100 tick and 10000 tick charts.

              Best regards.
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by priceisking, Today, 12:51 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_PaulH  
              Started by chartish, Today, 10:33 AM
              3 responses
              18 views
              0 likes
              Last Post chartish  
              Started by casabella, Today, 11:51 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_PaulH  
              Started by Johnny, Today, 11:42 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Jermaine  
              Started by habibalex, Today, 09:03 AM
              2 responses
              14 views
              0 likes
              Last Post sledge
              by sledge
               
              Working...
              X