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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Got it. Thanks for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          6 responses
          36 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          14 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X