Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disabling the strategy from the control panel does not close the open position.

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

    Disabling the strategy from the control panel does not close the open position.

    I'm running a strategy, and when I press the disable strategy checkbox in the control panel, the open position in the strategy doesn't close and remains open even though the strategy has been disabled. I also use the Chart Trader for various reasons, and when I press the CLOSE button, positions and all pending orders are closed. This is the behavior I want to happen when I disable the strategy from the control panel.

    I also tried placing closing orders and closing positions within the OnStateChange event when State == State.Terminated, but what happens is that it closes the position but after executing and disabling the strategy, it opens positions in the opposite direction. For example, if I had 2 longs, they close, and 2 shorts are opened.

    How can I achieve closing the open positions when disabling the strategy without opening other positions? Additionally, I would like to use the CLOSE button to close the strategy along with all positions and pending orders.

    I also explored the options in the Tools - Options menu under the strategy section, enabling and disabling the close entries and close exits options, but it doesn't yield the desired result.

    Please, if you could guide me on how to achieve what I need, I would greatly appreciate it. Thank you.

    #2
    Also help know what is the sequence of events fired when disable an strategy from control panel.
    Last edited by ervin; 08-27-2023, 10:30 PM.

    Comment


      #3
      Hello ervin,

      That would be expected, a position will remain open if you manually disable a strategy. It will only try to close a position if it has an error and is disabled by the error.. You need to manually close that position or the strategy would have needed logic to close that position before disabling it. You can't submit orders in State.Terminated, you would need to have the strategy running and close the position in its code and make sure its flat before disabling it.

      The best way forward for this situation is to use the chart trader to close the position while the strategy is running which will also disable the strategy.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Hi Jesse thank you,
        I have added the follow code into State.Terminated:

        if(Position != null && Position.MarketPosition != null && Position.MarketPosition == MarketPosition.Long)
        ExitLong();
        if(Position != null && Position.MarketPosition != null && Position.MarketPosition == MarketPosition.Short)
        ExitShort();​

        And close open positions, and also added code to close pending orders too, it's fine now. When disable strategy fron Control pannel closes position and pending orders.
        Now, When I press CLOSE button from Chart Trader If I have 2 Longs, closes 2 Longs and pending orders but Open 2 Shorts and the shorts remains after strategy is disabled. Why happens that? because I close positions in State.Terninate.

        What is the sequence of events fired on disabling strategy from Control Panel, and what are when press Close Buton?
        Thank you

        Comment


          #5
          Hello ervin,

          I dont know what logic you are using to know why that happens. The default action for a strategy is to disable when a position it created is manually closed. If it is doing something else that would be a result of your code.

          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sgordet, Yesterday, 11:03 AM
          5 responses
          26 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by faccipieri, Yesterday, 09:45 PM
          3 responses
          11 views
          0 likes
          Last Post bltdavid  
          Started by samish18, Yesterday, 06:05 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by kalalex, Today, 01:31 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by Mindset, 03-15-2025, 09:58 AM
          1 response
          20 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X