Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel Order won't work

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

    Cancel Order won't work

    Hi,
    This is somewhat a continuation to the previous thread: http://www.ninjatrader.com/support/f...119#post322119

    This is my code OnBarUpdate:
    Code:
    if(SomeCondition){
          CancelMyOrders();
          _order_ent = EnterLongStopLimit(_qnt, _price , _price, "Long");
    }
    ...
    if(SomeOtherCondition){
    CancelMyOrders();
    }
    And then this method:

    Code:
     private void CancelMyOrders(){
                
                if(_order_ent != null){
                    Print(Instrument.FullName + ": Cancel Entry Order");
                    CancelOrder(_order_ent);
                }
                if(_order_stp != null){
                    Print(Instrument.FullName + ": Cancel Stop Order");
                    CancelOrder(_order_stp);
                }
                if(_order_trg != null){
                    Print(Instrument.FullName + ": Cancel Target Order");
                    CancelOrder(_order_trg);
                }
    
            }
    The orders are created okay, but the cancel order won't cancel it. I still see them as Accepted in the Strategies tab.
    Also, I do get the debug line in the output window.

    What can be the reason?

    Thanks.

    #2
    Hello benharper,

    Thank you for your post.

    Do you see any errors messages listed in the Log tab of the NinjaTrader Control Center when running this strategy?

    What is the line in the Output window you refer to list?

    I look forward to your response.

    Comment


      #3
      No, I don't see any error message.
      I do see: PendingCancel and Cancel orders, but those are because I manually canceled the orders in the strategy tab.

      The line I refer to is the onw in my code:
      Code:
        if(_order_ent != null){
                      Print(Instrument.FullName + ": Cancel Entry Order");
                      CancelOrder(_order_ent);
                  }
      So, in the Output window I do see: QQQ: Cancel Entry Order

      But the orders are still active in the strategy tab.

      Comment


        #4
        Hello benharper,

        Thank you for your response.

        I recommend enabling TraceOrders on your Strategy to track the placement of your orders from the Output window.

        For information on TraceOrders please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3627

        Please let me know if you have nay questions.

        Comment


          #5
          Okay, I enabled it, and I will post again if I have more information.

          Comment


            #6
            Hi,
            I still have this issue. Order isn't canceled, and the trace isn't providing any more information.
            What I see in the output window is simply: "SPWR: Cancel Entry Order" which is my print line as you can see in the code below.

            Any ideas?

            Comment


              #7
              Ben,

              I can see you're checking for that it does not equal null, but after a previous order is canceled, are you explicitly setting this order to null?

              Code:
              protected override void OnOrderUpdate(IOrder order)
              		{
              			// Checks for all updates to _order_ent.
              			if (_order_ent != null && _order_ent == order)
              			{	
              				// Check if entryOrder is cancelled.
              				if (order.OrderState == OrderState.Cancelled)
              				{
              					// Reset _order_ent back to null
              					_order_ent = null;
                                              }
                                       }
                               }
              MatthewNinjaTrader Product Management

              Comment


                #8
                Yes, I do set it back to null (not shown in the code below). Please note that I do get the output line Print(Instrument.FullName + ": Cancel Stop Order"), so CancelOrder(_order_stp) is called. it is just not being canceled for a reason I don't understand.

                I added the code you provided, and I'll test it out.

                Comment


                  #9
                  I'm still having this issue. Is there another way to check why orders aren't canceled? Or maybe another way to cancel an order?
                  Right now, whenever the strategy is trying to cancel the order, I have to hit F5. That automatically cancels the order successfully. But obviously, this can't be a permanent solution.

                  Thanks.

                  Comment


                    #10
                    Hello benharper,

                    Thank you for your response.

                    The Log will show when the order is cancelled, if it is in fact cancelled.

                    In your original post you have the following line of code:
                    Code:
                    if(SomeCondition){
                          CancelMyOrders();
                          _order_ent = EnterLongStopLimit(_qnt, _price , _price, "Long");
                    }
                    So you are trying to enter at the same time you cancel you previous orders?
                    I recommend making sure the orders equal null and then place your new orders, this will make sure that your orders are cancelled before placing new orders and setting the iOrder to a new value instead of null:
                    Code:
                    if(_order_ent == null)
                    {
                    _order_ent = EnterLongStopLimit(_qnt, _price , _price, "Long");
                    }
                    Please let me know if this resolves this matter concerning whether orders are cancelled or not.

                    Comment


                      #11
                      The log doesn't say anything.
                      For example, exactly right now, I see in the output window: "CLR: Cancel Entry Order " which is my print line before I call CancelOrder.
                      In the log I see nothing. It's like the CancelOrder isn't sent.

                      Now I hit F5 on the strategy chart, and I see in the log:

                      2/28/2013 5:59:11 PM Strategy Enabling NinjaScript strategy 'mDummyEx/1d92274ced704e6aa506253b7cf6525e' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=False CalculateOnBarClose=False MaxRestarts=4 in 5 minutes

                      2/28/2013 5:59:35 PM Order Order='97fec2d8938d465e9388a0f3261c7eaa/U1120464' Name='Long' New state=PendingSubmit Instrument='CLR' Action=Buy Limit price=88.14 Stop price=88.01 Quantity=238 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''

                      2/28/2013 5:59:35 PM Order Order='76700410df9348f78f5e4182195d89ad/U1120464' Name='Short' New state=PendingSubmit Instrument='JCP' Action=SellShort Limit price=16.86 Stop price=16.94 Quantity=384 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''


                      And the order is canceled properly.

                      The reason I don't check the order to be null before EnterLongStopLimit is because there's a scenario in which the strategy modifies the order. So I found out that I don't even need to Cancel the order before creating a new. The strategy adjusting the current order well.
                      The problem is when I want to cancel the order completely.

                      Comment


                        #12
                        Hello benharper,

                        Thank you for your response.

                        As a test can you set the condition to first check that your iOrder is null before submitting a new order?

                        This means you will need to have the CancelOrder() called in it's own condition before you submit the new entry order.

                        Please let me know if the orders cancel properly when following this method.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by algospoke, Yesterday, 06:40 PM
                        2 responses
                        19 views
                        0 likes
                        Last Post algospoke  
                        Started by ghoul, Today, 06:02 PM
                        3 responses
                        14 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        45 views
                        0 likes
                        Last Post jeronymite  
                        Started by Barry Milan, Yesterday, 10:35 PM
                        7 responses
                        21 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by AttiM, 02-14-2024, 05:20 PM
                        10 responses
                        181 views
                        0 likes
                        Last Post jeronymite  
                        Working...
                        X