Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with ExitLongLimit/ExitShortLimit and with CancelOrder(stopLoss)

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

    Problem with ExitLongLimit/ExitShortLimit and with CancelOrder(stopLoss)

    Hi,

    I can exit fine with market orders e.g.
    Code:
    ExitLong(BarsInProgress, enOrder.Quantity, enOrder.Name + "Exit", enOrder.Name)
    However, when I try to exit with a Limit order:
    Code:
    ExitLongLimit(BarsInProgress, true, enOrder.Quantity, limitPrice, enOrder.Name + "Exit", enOrder.Name);
    It does not work. Tracing the order, it is apparently a success e.g.:
    Code:
    10/05/2011 14:45:00 Entered internal PlaceOrder() method at 10/05/2011 14:45:00: BarsInProgress=5 Action=Sell OrderType=Limit Quantity=739 LimitPrice=6.84 StopPrice=0 SignalName='CPE5Exit' FromEntrySignal='CPE5'
    However, the exit order does not appear in NinjaTrder control center.
    I tried getting rid of all my stop orders before exiting, e.g. using:
    Code:
                    foreach ( IOrder stopLoss in stopLosses ) {
                        Print("Cancelling: " + stopLoss);
                        CancelOrder(stopLoss);
                    }
    However, this does not seem to cancel the orders! So two problems really, not sure what is going wrong?!

    #2
    Hello,

    Thanks for the note.

    The biggest question I have and what I can see here is it looks like the order is a historical order not a live order. If the order is historical then it would not show in the orders tab in the control center.

    Also, it would not fill or cancel until the next OnBarUpdate(). However if your calling ExitLongStop() after you cancel the order this would then resubmit the order as well and keep it from cancelling.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      I'm using market replay. At the time I submit the ExitLongLimit order, the entryOrder is filled, and the position is still open. Remember, I can exit just fine using an ExitLong order.

      My code logic is Cancel(stopLoss) --> ExitLongLimit

      Not sure what is going wrong, confused ???!!!

      Comment


        #4
        Hello,

        Would need to find the order in trace order then or see the ignore message.

        The following you shown below is a sell limit. This is not a ExitLongStop as it would have a stop price and not just a limit price. Therefor this is some other order and not the one we are looking for.

        10/05/2011 14:45:00 Entered internal PlaceOrder() method at 10/05/2011 14:45:00: BarsInProgress=5 Action=Sell OrderType=Limit Quantity=739 LimitPrice=6.84 StopPrice=0 SignalName='CPE5Exit' FromEntrySignal='CPE5'
        BrettNinjaTrader Product Management

        Comment


          #5
          Hello,

          Please disregard the below for some reason I was thinking ExitLongStop not ExitLongLimit.


          Would want to take a look at full output of trace orders and the chart at this point and the exit code block. Will need more information to help you find the error.
          BrettNinjaTrader Product Management

          Comment


            #6
            Question 1: should I be able to cancel stop loss orders?

            e.g.
            Code:
                            //Cancel all our stops first:
                            foreach ( IOrder stopLoss in stopLosses ) {
                                Print("Cancelling: " + stopLoss);
                                CancelOrder(stopLoss);
                            }
            
            
                    protected override void OnOrderUpdate(IOrder order)
                    {
                        
                        //Store all our StopLosses in an array:
                        if (  order.Name == "Stop loss"  &&     order.OrderState == OrderState.Accepted    ) {
                            stopLosses.Add(order);
                        }
            }
            The above prints out like so, but no SL actually gets cancelled....

            Code:
            Cancelling: Order='fc4abf75efa84e7eaabdab6704f5c285/Replay101' Name='Stop loss' State=Filled Instrument='CCIH' Action=Sell Limit price=0 Stop price=15.53 Quantity=100 Strategy='iPEADv402' Type=Stop Tif=Gtc Oco='086ac0e516474435b059eba80f3c7f55-343' Filled=100 Fill price=15.48 Token='fc4abf75efa84e7eaabdab6704f5c285' Gtd='01/12/2099 00:00:00'
            Cancelling: Order='2fd3279983ce4744985a03acc7ad0bd0/Replay101' Name='Stop loss' State=Filled Instrument='ES' Action=Sell Limit price=0 Stop price=5.68 Quantity=100 Strategy='iPEADv402' Type=Stop Tif=Gtc Oco='c809339a8b684d6cb2b0d7e585aca7ad-343' Filled=100 Fill price=5.67 Token='2fd3279983ce4744985a03acc7ad0bd0' Gtd='01/12/2099 00:00:00'
            .....

            Comment


              #7
              Question 2: Will the existence of StopLoss orders affect my attempt to ExitLongLimit. E.g. will the existence of a stoploss be a problem with Internal Order Handling Rules, and do I need to cancel my stoplosses?

              Comment


                #8
                Hello,

                Question 1: Yes you can cancell these orders. As long as you have the right order ID.

                Question 2; Yes this can be the case please see below. I bolded the section that affects you.



                :


                Methods that generate orders to enter a position will be ignored if:
                A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
                A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
                The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                The entry signal name is not unique

                Methods that generate orders to exit a position will be ignored if:
                A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                A position is open and an order submitted by a set method (SetStopLoss() for example) is active

                Set() methods that generate orders to exit a position will be ignored if:
                A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active
                BrettNinjaTrader Product Management

                Comment


                  #9
                  Thats great, thanks for the info.

                  So I cannot ExitLongLimit because I have StopLosses in place.
                  Therefore my primary problem is that I cannot remove my StopLosses for some reason.

                  As can be seen from the code:
                  Code:
                                  //Cancel all our stops first:
                                  foreach ( IOrder stopLoss in stopLosses ) {
                                      Print("Cancelling: " + stopLoss);
                                      CancelOrder(stopLoss);
                                  }
                  
                  
                          protected override void OnOrderUpdate(IOrder order)
                          {
                              
                              //Store all our StopLosses in an array:
                              if (  order.Name == "Stop loss"  &&     order.OrderState == OrderState.Accepted    ) {
                                  stopLosses.Add(order);
                              }
                  }
                  Note that I have set TraceOrders = true;
                  I certainly have the correct IOrder objects, as my print statement is correct (see below).
                  However, the order does not get cancelled.
                  Also, TraceOrders does not print any statements out, so it is difficult to trace the problem!

                  Code:
                  Cancelling: Order='fc4abf75efa84e7eaabdab6704f5c285/Replay101'  Name='Stop loss' State=Filled Instrument='CCIH' Action=Sell Limit  price=0 Stop price=15.53 Quantity=100 Strategy='iPEADv402' Type=Stop  Tif=Gtc Oco='086ac0e516474435b059eba80f3c7f55-343' Filled=100 Fill  price=15.48 Token='fc4abf75efa84e7eaabdab6704f5c285' Gtd='01/12/2099  00:00:00'
                  Cancelling: Order='2fd3279983ce4744985a03acc7ad0bd0/Replay101'  Name='Stop loss' State=Filled Instrument='ES' Action=Sell Limit price=0  Stop price=5.68 Quantity=100 Strategy='iPEADv402' Type=Stop Tif=Gtc  Oco='c809339a8b684d6cb2b0d7e585aca7ad-343' Filled=100 Fill price=5.67  Token='2fd3279983ce4744985a03acc7ad0bd0' Gtd='01/12/2099 00:00:00'
                  .....

                  Comment


                    #10
                    AntiMatter, you could unfortunately not CancelOrder / unSet the Set() stop losses - please protect your position using the Exit() methods and then CancelOrder as needed to enter new positions.

                    Comment


                      #11
                      Ah yes, thats the problem.

                      Now I use enter my stops manually using ExitLongStop
                      And now I can exit them, which means the subsequent ExitLongLimit order works correctly

                      Thanks for helping get to the bottom of it all.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by argusthome, Yesterday, 10:06 AM
                      0 responses
                      14 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      11 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      9 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post TheRealMorford  
                      Started by Mindset, 02-28-2026, 06:16 AM
                      0 responses
                      31 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Working...
                      X