Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder() help needed

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

    CancelOrder() help needed

    Hi,

    I have adapted the following code from your SampleCancelOrder for NT7:

    protected override void OnBarUpdate()
    {
    // First, we need a simple entry. Then entryOrder == null checks to make sure entryOrder does not contain an order yet.
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    // Check IOrder objects for null to ensure there are no working entry orders before submitting new entry order
    if (entryOrder == null)
    {
    if (long0)
    entryOrder = EnterLongStop(price,"Long 0");
    else if (long1)
    entryOrder = EnterLongStop(price,"Long 1");
    else if (short0)
    entryOrder = EnterShortStop(price,"Short 0");
    else if (short1)
    entryOrder = EnterShortStop(price,"Short 1");
    }

    // If cancel true, cancel the order.
    else if (entryOrder != null && cancel)
    {

    CancelOrder(entryOrder);
    Print("cancel Order " + entryOrder);
    }
    }
    else if (cancel)
    {
    ExitLong();
    ExitShort();
    }
    }

    protected override void OnOrderUpdate(IOrder order)
    {
    // Checks for all updates to entryOrder.
    Print("OrderUpdate " + order.OrderState.ToString());
    if (entryOrder != null && entryOrder == order)
    {
    // Check if entryOrder is cancelled.
    if (order.OrderState == OrderState.Cancelled)
    {
    // Reset entryOrder back to null
    entryOrder = null;
    }
    }
    }

    The problem I'm having is that the order is never cancelled. The print statements indicate that CancelOrder(entryOrder) keeps being executed on each bar update, but there is never an update to the order status, and on a second chart with ChartTrader open, I can see the order still sitting there.

    How can I fix this?

    Thanks

    #2
    Hi palinuro, do you see the stop entry still listing as working when you try to cancelOrder it as would that be the protective stop / target orders the script would normally submit to? Those would not be cancelled with your call to the entryOrder IOrder.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi palinuro, do you see the stop entry still listing as working when you try to cancelOrder it as would that be the protective stop / target orders the script would normally submit to? Those would not be cancelled with your call to the entryOrder IOrder.
      Hi Bertrand,

      I'm not quite sure what you mean. There's no protective stop or target orders, that's a stop entry order, which isn't being canceled. Using TraceOrder just referred me to the Internal Order Handling section of Help, which talks about exiting an order, but not canceling.

      I found last night that changing the entry order method to a signature with "GTC = true" solved the problem, but having to do this isn't in accord with the code in the example given.

      Comment


        #4
        Thanks for clarifying, as the original sample script would contain those stop / target exits...I see you're not working with the liveUntilCancelled overload here for the stop entry, this would mean it expires automatically on the next OnBarUpdate() if not resubmitted - perhaps you can attach me the script you're now using in testing so I can give it a run here?
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by zstheorist, Today, 07:52 PM
        0 responses
        3 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        149 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        5 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        5 views
        0 likes
        Last Post tkaboris  
        Working...
        X