Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close Positions, Orders, Strategy on Friday

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

    Close Positions, Orders, Strategy on Friday

    I have the following code to close all open positions, close all active orders, and to disable the strategy.

    The code closes positions and disables strategy, but it doesn't remove active orders. My Stop Loss and Profit target orders remain open after the strategy is disabled.

    Is there any way I can get a clean close of all active orders.


    //Friday Code
    if (Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) >= 133000)
    {
    if (Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong(@"LongPos");
    }
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort(@"ShortPos");
    }
    if (State == State.Realtime)
    {
    SetState(State.Terminated);
    Print("Condition not met. Disabling Strategy" + Time[0].ToString());
    return;
    }
    }

    #2
    Hello ajsdnyyrr1234DDf,

    Thank you for the post.

    Can you tell me, are you currently using the Set methods for the target and stop loss or are you using other types of orders? Most commonly you can use CancelOrder for any orders that need to be cancelled in the script, but this requires a Order object.

    Another item to check would be the options for strategies in the options menu. There is an option to cancel entry orders and exit orders upon disabling the strategy. Are you currently using this option? https://ninjatrader.com/support/help...riptProperties

    I look forward to being of further assistance.

    Comment


      #3
      Yes. I am using Set methods, SetProfitTarget() and SetStopLoss() to set StopLoss and TargetProfits. I am not using Order Objects.

      How do I access The Options screen?

      Comment


        #4
        Hello ajsdnyyrr1234DDf,

        you can access the options menu from the control center Tools -> Options menu. Then the Strategies tab and finally the checkboxes: Cancel entry orders ... Cancel exit orders...


        I look forward to being of further assistance.

        Comment


          #5
          Got it. Thanks for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          65 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X