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 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
        Paul H.NinjaTrader Customer Service

        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
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by WeyldFalcon, 12-10-2020, 06:48 PM
            14 responses
            1,428 views
            0 likes
            Last Post Handclap0241  
            Started by DJ888, 04-16-2024, 06:09 PM
            2 responses
            9 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            41 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            2 responses
            16 views
            0 likes
            Last Post bill2023  
            Working...
            X