Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

cant cancel IB orders when get order rejected error

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

    cant cancel IB orders when get order rejected error

    some live orders in IB are not being canceled.

    I am working with StopLimit orders having a limit below the stop (negative)
    the order is accepted by the IB.
    in some cases when the stop is triggered but the limit is not yet reached , I sometimes want to replace the order with a new one.
    this is when the IB rejects the updated order.
    I then trap the error in OnOrderUpdate and have this code :
    Code:
    if (entryOrder != null && entryOrder == order && order.OrderState == OrderState.Rejected)
      {
        // Rejection handling    
        iPrint("REJECTED - Previous order was already triggered so we cancel and resubmit ");
        foreach (Order openorder in Orders)
         {
           Print(openorder.Name + " " + openorder.OrderState);
           CancelOrder(openorder);
         }
    
           EnterLongStopLimit(0 , true , OffsetTradeSize , LimitLevelforLONG , StopLevelforLONG   , "FCMoveLong");
    
    }
    ​
    the old order is not being canceled. What am I doing wrong ?

    #2
    Hello dadarara,

    If IB is rejecting the order change you would need to review the reason in the log. If you are trying to change an order that is in the process of filling that may be preventing you from doing a change. If the order has already filled or is in process the cancel order would not work.

    I also see that you are working with the Orders collection which is not a documented part of strategies. That exists but is not documented for any type of use cases. I would suggest to try and instead store the order to a variable in OnOrderUpdate and then use that variable to cancel it to see if that works better. It looks like your doing that for entryOrder already so it would be the same general concept to store a variable for any other order you use.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    11 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    16 views
    0 likes
    Last Post AaronKoRn  
    Working...
    X