Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pending order cancellen when strategy disabled/enabled

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

    Pending order cancellen when strategy disabled/enabled

    I'm running a strategy that puts in pending profit orders. When I disable then strategy the order is still there, but when I enable the strategy again the pending order is cancelled.

    Why is that? The portfolio position has not changed. I would like the pending order to still be there, or at least be resubmitted.

    I use the SetProfitTarget within the OnBarUpdate method. Is this the right place for it? Maybe there is a OnStrategyEnabled method or something I should put it in?

    I know that when I enable "Submit historical working order" the pending orders come back. But what will happen to unfilled orders that open a position? I don't want orders that have expired already to be opened (at much different price than strategy intended).

    I could set the BarsIndex in the EnterLong() method to 0 so that the order expires at the end of the bar, but that will force me to use a limit order because at market I could risk a worse fill.

    Looking forward to hear best practises in this.
    Last edited by siroki; 10-14-2014, 07:24 AM.

    #2
    Hello siroki,

    Thanks for your post.

    From your description I think you are describing the 'Wait until flat before executing live, Sync account position = false' setup in the first part of your first question and 'Immediately submit live working historical orders, Sync account position = false' setup in your third question.

    With 'Wait until flat before executing live, Sync account position = false' in this situation when your strategy starts it will check for any active orders previously generated by the strategy on your account and cancel those first.
    If the Strategy Position is flat, then the Account Position and Strategy Position are assumed to be in sync with each other. The next order placed by your strategy would be placed as a live order to your account.
    If the Strategy Position is not flat, the strategy will place all trades in a "virtual" sense until the Strategy Position reaches or crosses a flat state. Once a flat state is achieved the Strategy Position will be assumed to be in sync with the Account Position and all future orders will be placed live

    With 'Immediately submit live working historical orders, Sync account position = false', in this situation any active orders on the account previously generated by the strategy that does not match* an active strategy order will be cancelled. The matching active orders on the account will then be mapped to the active strategy orders. Any remaining active strategy orders that cannot be successfully paired will be submitted live and the strategy will begin managing your Strategy Position assuming your Account Position is in sync with it.

    Below is a link to the help guide.
    http://www.ninjatrader.com/support/h..._positions.htm

    This means you should check the value of the conditions in your strategy and ensure the the strategy is showing it should be submitting orders at that time.

    Also, in the Tools -> Options... -> Strategies tab -> NinjaScript sub-tab -> Order handling, do you have Cancel entry orders when a strategy is disabled or Cancel exit orders when a strategy is disabled checked?


    SetProfitTarget and SetStopLoss can be used pretty much in any method. OnBarUpdate, OnOrderUpdate, OnExecution, OnMarketData, OnMarketDepth, OnStartUp()..

    The placement for SetProfitTarget and SetStopLoss will depend on what kind of logic you want your strategy to have. If you want the profit target set after an order is filled, set the target in OnExecution. If you set the profit target in OnStartUp() it will set an initial value. (You can also set it in Initialize() but OnStartUp() is preferred.)

    When calling EnterLong(int barsInProgressIndex, int Quantity, string SignalName) the BarsArray / BarsInProgress index is used to choose which added data series the order will be submitted to. This requires multiple data series to be added to strategy.

    BarsArray - http://www.ninjatrader.com/support/h.../barsarray.htm

    BarsInProgress - http://www.ninjatrader.com/support/h...inprogress.htm

    EnterLong - http://www.ninjatrader.com/support/h.../enterlong.htm

    The liveUntilCancelled bool when true keeps a limit, stop, and stop limit order alive after a bar closes.
    EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)
    EnterLongLimit - http://www.ninjatrader.com/support/h...rlonglimit.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea for your thorough answer. Very helpful indeed.

      Comment


        #4
        help with getting rid of pending orders

        Hi,

        I have these "pending orders." Cannot cancel them. They don't seem to cause any problem but are annoying. Can anyone advise me how to get rid of them?

        Thanks
        Attached Files

        Comment


          #5
          Hello westcoastjoe,

          Thanks for your post.

          First, if this is a live trade please contact your broker to manage/verify the position/orders

          Once you have closed the position with your broker please repair your database to remove the order from NinjaTrader.

          To repair your database please go to Tools -> Options -> Data -> and click Repair DB.

          If the order was submitted to the sim101 account please reset the sim101 account.

          To reset the sim101 account please go to Tools--> Options--> Simulator--> and click Reset
          Click here for more information on the Sim101 account

          Comment


            #6
            Thanks

            Thanks, Brandon.

            Did a reset once before. Hopefully my templates will not be erased. Seems to me the reset does not affect them.

            Joe

            Comment


              #7
              Hello westcoastjoe,

              Thanks for your reply.

              If that does not resolve this please let us know. That is correct, it will not affect your templates.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              558 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X