• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel existing profit and stoploss orders

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

    Cancel existing profit and stoploss orders

    Working on a strategy that could be short at some part of the day with existing profittarget and stoploss orders. I'd like to experiment with canceling the existing stop orders and reenter marketstop order with new set of stoploss and profittargets to go long.

    I'm currently using managed order approach. Is it possible to cancel these existing orders using managed, or do I need to go the unmanaged route?

    I've looked at the SampleCancelOrder example but does not seem to apply to what I am trying to do.

    Help always appreciated.

    #2
    Hello RandyT,

    Yes, it is possible to cancel an order in the Managed approach.

    You would need to assign the order to an Order variable in OnOrderUpdate. Then you can call CancelOrder() and supply the variable holding that order object.

    After cancelling, you would want to ensure that the order becomes State.Cancelled in OnOrderUpdate.

    Normally, I would link the SampleCancelOrder_NT8 strategy in the help guide because this demonstrates how to cancel a limit order using the managed approach.

    Can you further detail why this is not a good example of how to cancel an order?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by RandyT View Post
      Working on a strategy that could be short at some part of the day with existing profittarget and stoploss orders. I'd like to experiment with canceling the existing stop orders and reenter marketstop order with new set of stoploss and profittargets to go long.
      Sounds to me like you want to automatically reverse the current position.

      Originally posted by RandyT View Post
      I'm currently using managed order approach. Is it possible to cancel these existing orders using managed, or do I need to go the unmanaged route?
      Yes, of course, it's possible to cancel orders using Managed mode. As support so indicates, the SampleCanceOrder example shows you precisely how to do this.

      Originally posted by RandyT View Post
      I've looked at the SampleCancelOrder example but does not seem to apply to what I am trying to do.
      That's because what you're trying to do (I think) is automatically reverse the position.

      But, you're asking a super low level specific question like 'How do I cancel an order in Managed mode?' -- which is somewhat related to auto-reverse, since you would cancel existing orders before reversing the position, so you're on the right track --

      Thus, if I may intervene a little, is your question really about reversing the current position?

      That is a much different question ...

      Comment


        #4
        bltdavid,

        Your input is appreciated here.

        I answered the question directly without thinking about the goal, which is to reverse the position.

        RandyT, NinjaTrader will automatically reverse the position using the managed approach if an entry order is called in the opposite direction of a position. If the position is long and you call EnterShort(), NinjaTrader will send a 'Close position' order to close the current position, and a second 'Sell short' order to enter into the short position. There isn't any need to exit the first long position to reverse to short (specifically with the managed approach).

        Any working stop losses or profit targets that are attached to that entry will automatically be cancelled.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks to you both.

          Actually not trying to reverse the position.

          FWIW, researching a breakout strategy.

          I have a short position that is likely not working out, but may still get a few more ticks...

          I want to remove the stoploss on this open short position.
          I want to pull in the short profit target.
          I want to create a longstopmarket and associated stoploss and profit targets that brackets the current range based on a potential long breakout. Effectively replacing the stoploss on the short position with this longstopmarket.

          I've added the following bit of code based on what I could gleen from the example. Still not having the effect I am looking for. Still debugging here.

          Code:
          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                  {
                      if (order.Name == "Stop loss")
                      {
                          if (stopOrder == null)
                          {
                              stopOrder = order;
                          }
                          else if (stopOrder != null && order.OrderState == OrderState.Cancelled)
                          {
                              stopOrder = null;
                          }
                      }
                  }

          Comment


            #6
            Hello RandyT,

            You will not be able to cancel a stop loss order that's placed with SetStopLoss() or SetTrailStop(), or SetProfitTarget().
            But they will cancel automatically when the entry is cancelled or the position is closed.

            If you have Exit orders instead, these can be cancelled with CancelOrder().

            If the position is not changing, why cancel orders and resubmit them instead of just moving these to different prices?
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ArmKnuckle, Today, 07:55 PM
            0 responses
            1 view
            0 likes
            Last Post ArmKnuckle  
            Started by Nabil, Today, 07:46 PM
            0 responses
            1 view
            0 likes
            Last Post Nabil
            by Nabil
             
            Started by mohdhm, Today, 04:37 PM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by trader14, Yesterday, 08:23 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by bigsurftrader, 02-24-2017, 12:23 AM
            4 responses
            1,162 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X