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 close

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

  • roblogic
    replied
    Originally posted by NinjaTrader_AlanP View Post
    Hello travelingsalesman,

    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,

    Hello,

    In this particular situation:

    Resetting a variable in Bars.IsFirstBarOfSession is clear but how a bool can be reset if, IsExitOnSessionCloseStrategy == true and the X seconds of ExitOnSessionCloseSeconds have elapsed to prevent new entries?

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    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.

    Leave a comment:


  • roblogic
    replied
    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?

    Leave a comment:


  • travelingsalesman
    replied
    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.

    Leave a comment:


  • travelingsalesman
    replied
    awesome thanks for that info

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    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,


    You could also use a time filter. An example of using a time filter can be found below,


    Please let us know if you need further assistance.

    Leave a comment:


  • travelingsalesman
    replied
    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?

    Leave a comment:


  • NinjaTrader_ChelseaB
    started a topic Exit on close

    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://drive.google.com/file/d/1KP5...Wh1Zp7s3X/view

    Attached is the PreventEntryAfterExitOnCloseExample tested in the video.
    PreventEntryAfterExitOnCloseExample_NT8.zip
    ExitOnCloseTest_NT8.zip
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 06-02-2021, 08:52 AM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by junkone, Today, 11:37 AM
0 responses
2 views
0 likes
Last Post junkone
by junkone
 
Started by quantismo, 04-17-2024, 05:13 PM
5 responses
34 views
0 likes
Last Post NinjaTrader_Gaby  
Started by proptrade13, Today, 11:06 AM
1 response
6 views
0 likes
Last Post NinjaTrader_Clayton  
Started by love2code2trade, 04-17-2024, 01:45 PM
4 responses
34 views
0 likes
Last Post love2code2trade  
Started by cls71, Today, 04:45 AM
2 responses
10 views
0 likes
Last Post eDanny
by eDanny
 
Working...
X