Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disable Strategy - Wait Until Flat

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

    Disable Strategy - Wait Until Flat

    Is there an option or feature to set "wait until flat" for disabling a strategy that has an open position? If not, I'd like to propose this as a new feature request. For example, when disabling a running strategy that currently has an open position, the system should prompt "Disable immediately or wait until flat." If this is already possible, then can someone please tell me how?

    #2
    Hello mase2005,

    Thank you for your post.

    This would be possible using custom NinjaScript logic. If you have a programming background and the strategy is something you have developed yourself, we would be glad to provide you links to resources and samples that would help you write the code yourself, or we can provide you with resources to find a programmer to create the script for you. Please let me know if either of these options interests you.

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Yes, I am a coder. If you'll kindly point me in the right direction Thank you!

      Comment


        #4
        Hello mase2005,

        Thank you for your reply.

        The CloseStrategy() method cancels all working orders, closes any existing positions, and disables the strategy. It may also be overridden with custom logic if desired. Here is the help guide page:


        In your case, if you are wanting to disable a strategy under certain conditions and only when it is flat, I suggest checking in OnPositionUpdate() if the position is flat (along with any other desired conditions) and then calling CloseStrategy() to disable the strategy. Here is a snippet of what that might look like:

        Code:
        protected override void OnPositionUpdate(Cbi.Position position, double averagePrice,
              int quantity, Cbi.MarketPosition marketPosition)
        {
          if (position.MarketPosition == MarketPosition.Flat) // feel free to add additional conditions here
          {
            CloseStrategy()
          }
        }​
        Additionally, we have a basic and advanced sample for halting a strategy once user defined conditions are met:


        You could certainly add a check for if (position.MarketPosition == MarketPosition.Flat) inside of the conditions as well.

        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Perfect. Thank you!!!

          Comment


            #6
            To clarify: is the CloseStrategy() function called when I disable a strategy from the Control Center (by clicking the checkbox or right-click and choose "disable")? I tried to override the CloseStrategy() function, but it seems to be ignoring my custom logic...

            Comment


              #7
              Hello mase2005,

              No that would not be called by unchecking it, CloseStrategy is for use in your code specifically. When you uncheck the strategy any logic in the override won't be called. The only items that would happen would be cancelling of working orders if you have those options set in the Tools > Options > Strategies menu. https://ninjatrader.com/support/help...strategies.htm

              JesseNinjaTrader Customer Service

              Comment


                #8
                Is there any other way for me to interact with a running strategy? Say, change/set a variable to queue my custom shutdown sequence? Ideally, I want to be able to disable a strategy from Control Center and it 1) not allow any new open orders 2) cancel any open orders, and 3) allow the strategy to continue running until all open positions are properly exited according to the strategy

                Comment


                  #9
                  Hello mase2005,

                  Thank you for your reply.

                  What you are describing sounds like it could be achieved with a custom add-on. You could create a window with buttons or a checkbox to toggle bools between true/false. Your entries could be set up so they are only submitted if the bool is either true or false, then have logic to cancel orders when the bool is toggled yet then keep the exit logic set up for the open positions to close according to your original logic.

                  When developing add-ons, the Account class is used to submit and manage orders:


                  We have a section of the help guide dedicated to information for developing add-ons, including a sample script that you can import by clicking the "AddOn Framework NinjaScript Basic" link on this page:


                  Please let us know if we may be of further assistance.
                  Emily C.NinjaTrader Customer Service

                  Comment


                    #10
                    Thank you! I'll give this a look!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Waxavi, Today, 02:10 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post Waxavi
                    by Waxavi
                     
                    Started by TradeForge, Today, 02:09 AM
                    0 responses
                    8 views
                    0 likes
                    Last Post TradeForge  
                    Started by Waxavi, Today, 02:00 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post Waxavi
                    by Waxavi
                     
                    Started by elirion, Today, 01:36 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post elirion
                    by elirion
                     
                    Started by gentlebenthebear, Today, 01:30 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post gentlebenthebear  
                    Working...
                    X