• 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 all position on the given time.

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

    Exit all position on the given time.

    Hello.
    How to exit all position at the given time?

    #2
    Hello Czarek,

    Are you attempting to close all positions for all accounts on all instruments? (all positions)

    Or are you wanting to close the singular position of the strategy? (you have posted in the strategy development section of the forums)

    To close the position of the strategy at a specific time in OnBarUpdate():

    if (ToTime(Time[0]) == 90000)
    {
    if (Position.MarketPosition == MarketPosition.Long)
    ExitLong();
    if (Position.MarketPosition == MarketPosition.Short)
    ExitShort();
    }

    This would close an open position at 9:00 AM .

    Below are public links to the help guide on Time[0], ToTime(), Position, MarketPosition, ExitLong(), and ExitShort().
    https://ninjatrader.com/support/help...eries_time.htm
    https://ninjatrader.com/support/help...-us/totime.htm
    https://ninjatrader.com/support/help...s/position.htm
    https://ninjatrader.com/support/help...etposition.htm
    https://ninjatrader.com/support/help...s/exitlong.htm
    https://ninjatrader.com/support/help.../exitshort.htm

    Also, below is a public link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      If I want to close position in Strategy Analyzer 1 hour before session closes - how to accomplish it programmatically?

      I tried updating Property "ExitOnSessionCloseSeconds" to 3600 - but it doesn't seem to work in Strategy Analyzer..

      Note, sometimes there are holidays (so sessions are shorter than usual) - I want to accomplish these as well (ideally I want to know programmatically whether that current session has different trading hours than regular one...)

      Thank you

      Comment


        #4
        Hello music_p13,

        You are correct, ExitOnSessionCloseSeconds is a real-time only property, it will not have any effect on your ExitOnSessionClose time in backtesting processing historical data.
        https://ninjatrader.com/support/help...oseseconds.htm

        You can use a session iterator to get the time of the session close. The PreventEntryAfterExitOnCloseExample is a good example of getting the time of the session close. (It prevents new entries after the session close until the new session)
        https://ninjatrader.com/support/foru...058#post516058

        The current session's close time can be compared to the <tradingHours>.Sessions collection.
        https://ninjatrader.com/support/help...s_sessions.htm

        You would likely need to loop through each day and compare that to this sessions close time .DayOfWeek to know that its the session for today.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by aprendiz, Today, 08:04 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Martin89, Today, 02:09 AM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by tallpaw, Today, 07:20 AM
        3 responses
        9 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by leodrz, Yesterday, 10:26 PM
        2 responses
        32 views
        1 like
        Last Post leodrz
        by leodrz
         
        Started by Trade95, Yesterday, 05:38 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_EricB  
        Working...
        X