Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit before session close

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

    Exit before session close

    Hello,
    How do I use ToTime() or other logic in my strategy to exit all open positions at session close? Using:
    Code:
    if ((ToTime(Time[0]) == 155500) && Position.MarketPosition == MarketPosition.Long)
    			{
    				Draw.ArrowDown(this, @"MyStratArrow down", false, 0, 0, Brushes.Red);
    				ExitLong(Convert.ToInt32(orderqty), @"ExitLong", @"Buy");
    			}
    to exit at 3:55pm is being ignored by the strategy, which continues to execute the running strategy and I still have to manually close the running position. I would like to exit at 3:55pm each day.
    Many thanks.

    #2
    Originally posted by aaadetos View Post
    Hello,
    How do I use ToTime() or other logic in my strategy to exit all open positions at session close? Using:
    Code:
    if ((ToTime(Time[0]) == 155500) && Position.MarketPosition == MarketPosition.Long)
    			{
    				Draw.ArrowDown(this, @"MyStratArrow down", false, 0, 0, Brushes.Red);
    				ExitLong(Convert.ToInt32(orderqty), @"ExitLong", @"Buy");
    			}
    to exit at 3:55pm is being ignored by the strategy, which continues to execute the running strategy and I still have to manually close the running position. I would like to exit at 3:55pm each day.
    Many thanks.
    There would have to be data at 155500 exactly for that code to hit.

    I'm a little more forgiving, 20 minutes, in case of disconnects or internet issues or whatever.


    Code:
    			if (   ToTime(Time[0]) >= ToTime( 15, 50, 00)
    				&& ToTime(Time[0]) <= ToTime( 16, 10, 00) )
                    { 
                            // EXIT
    
    			{

    Comment


      #3
      Thanks sledge,
      What about using the order handling strategy property and setting the Exit on session close seconds to say 300 or whatever number? This would work too right? Haven't tested it yet.

      Comment


        #4
        Hello aaadetos,

        Thanks for your post.

        Member sledge has provided sage advice to use a time range to ensure you get multiple opportunities.

        Using ExitOnClose will provide the same functionality.

        A 3rd option to consider is the use of the "Auto Close" function (Not available for Direct License users). This can be found in Tools>options>Trading. Please see: http://ninjatrader.com/support/helpG...ns_trading.htm

        Comment


          #5
          Thanks a lot Paul. I'll definitely try the Auto Close function. But wouldn't ExitOnClose exit at session close?

          Comment


            #6
            Hello aaadetos,

            Thanks for your reply.

            Correct, that is the intent of ExitOnClose order handling. Please see the helpguide here: http://ninjatrader.com/support/helpG...t_strategy.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            54 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            72 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X