Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit order is being ignored

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

    Exit order is being ignored

    When I place a limit order to open a position, I would also like to place a limit order to close, coexisting with the stop loss order. My position successfully opens and the the stop loss order is placed, but the NT log indicates my exit order is being ignored.

    I'm setting my stop loss as follows:

    Code:
    else if (State == State.Configure)
                {
                    SetStopLoss(CalculationMode.Currency, stopLossCurrency * orderQuantity);
                }
    ​

    I'm trying to place a limit order to close as follows:

    Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity,
                MarketPosition marketPosition, string orderId, DateTime time)
            {
                if (execution.Order.Name == longSignalName) // If long position has just opened
                {
                    ExitLongLimit(predHigh, longSignalName);  // Place a limit sell order.  (Method is ignored if no long position exists.)
                }
                else if (execution.Order.Name == shortSignalName)
                {
                    ExitShortLimit(predLow, shortSignalName);  // Place a limit buy-to-close order.  (Method is ignored if no short position exists.)
                }
            }
    Ideally, I'd like to place my open/close pair as an OTA (one triggers another) order but I don't think that's possible in NT. My questions are:
    1. Is it actually possible to place an OTA order? If so, how?
    2. What is the most appropriate way to place a close limit order while keeping my stop loss order in place?

    #2
    Hello Red_70,

    Thank you for your post.

    The reason your exit order is being ignored is because of the internal order handling rules listed here:


    Essentially, you may not have both a stop loss order from SetStopLoss() and an exit order with an Exit() method both in place at the same time. You will need to either remove the SetStopLoss() in State.Configure or remove your ExitLongLimit() and ExitShortLimit() order methods as the Set() method and Exit() methods could conflict with each other.

    Please describe the behavior you are referring to as OTA in more depth. You could certainly set up conditions so that once a long or short position exists, an exit order is submitted. Is this what you are referring to, or is OTA something else?

    I look forward to your reply.

    Comment


      #3
      HI Emily,

      Thanks for your explanation. By OTA I'm referring to a complex type of order in which the order to open is sent to the exchange while the order to close is held until the first order is filled. Then the order to close would be submitted to the exchange. So, basically, the order specification would allow simultaneously submitting both orders to the broker. (Maybe this is better described as a contingent order?)

      If I have an open stop loss order, what would be the appropriate way to cancel it prior to submitting my limit close order?

      Comment


        #4
        Hello Red_70,

        Thank you for your reply.

        Based on your description, you are correct that OTA order functionality is not specifically supported by NinjaTrader. That said, you may monitor your orders with OnOrderUpdate() and OnExecutionUpdate() to monitor order states and receive executions/fills of orders to submit protective orders as demonstrated in the following reference sample:


        Are you using your limit close order as a sort of Profit Target in conjunction with the stop loss order? It is typically best to either use SetStopLoss() and SetProfitTarget() together or to use Exit methods exclusively for your own stop/target orders as shown in the example I just linked. There is a CancelOrder() method available, though you must track the Stop loss order object in order to use it for an order generated by SetStopLoss():
        CancelOrder() - https://ninjatrader.com/support/help...ancelorder.htm
        The order class - https://ninjatrader.com/support/help...#TheOrderClass


        Please let me know if I may be of further assistance.

        Comment


          #5
          Emily,

          This is helpful information. Would it be possible to use SetProfitTarget() using a value that is determined within OnBarUpdate()? That is, my trading strategy doesn't yet have the profit target calculated when the current state equals Configure.

          Comment


            #6
            Hello Red_70,

            Thank you for your reply.

            Yes, SetProfitTarget() may be used dynamically in OnBarUpdate(). It is important to reset the price/offset value when the position is flat or else the last value when SetProfitTarget() was called will be used for the next position that is opened. For more information on SetProfitTarget():


            Please feel free to reach out with any additional questions or concerns.

            Comment


              #7
              Ok, thanks for clarifying. One more question: If I wanted to submit a market close order at a specific time of day for an existing long position, while my profit target order and stop loss orders are live, would I need to first cancel those orders using the following approach?

              Code:
              if (timeOfDay == closePositionTimeOfDay)
              {
                  CancelOrder('Profit target');
                  CancelOrder('Stop loss');
                  ExitLong();
              }​
              Or is there a better way of accomplishing this?

              Comment


                #8
                Hello Red_70,

                Thank you for your patience.

                I am now seeing that my previous statement is incorrect:
                There is a CancelOrder() method available, though you must track the Stop loss order object in order to use it for an order generated by SetStopLoss():
                Orders that were generated by the Set() methods may not be canceled. The price may be changed, though if you want an order that is able to be canceled you will have to use an Exit method and then you could use CancelOrder() on the order object generated by the Exit method. I apologize for any confusion or inconvenience caused by providing inaccurate information. If you are wanting to have a position closed at a certain time of day, I suggest not using the Set() methods and instead using the Exit methods for your stop loss and profit target orders. That way, if the closePositionTimeOfDay is met you may cancel the working Exit orders and submit a market exit such as ExitLong() or ExitShort() to close the position. This could ultimately look like a combination of the ideas demonstrated in the reference sample I previously provided for using OnOrderUpdate() and OnExecutionUpdate() to submit protective orders as well as using a time filter to limit trading hours. Both samples have been linked below:
                https://ninjatrader.com/support/help...and_onexec.htm
                https://ninjatrader.com/support/help...to_limit_t.htm

                I am also editing my response to add the following information:
                The default behavior is to cancel limit orders if the conditions to trigger the order are no longer true. Otherwise, you may submit an order that stays active until it is cancelled by setting isLIveUntilCancelled to true. The following sample strategies help to demonstrate these concepts:



                Please let us know if we may be of further assistance.
                Last edited by NinjaTrader_Emily; 07-24-2023, 02:08 PM.

                Comment


                  #9
                  Emily,

                  Thank you for the correction and for all of your help with this issue. I'll let you know if I encounter further problems.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  50 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  126 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  69 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  42 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X