Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder Not working

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

    CancelOrder Not working

    hello,

    here is my code:
    protected override void OnBarUpdate()
    {
    if (State == State.Historical)
    return;

    myEntryOrder=EnterLongMIT(13930.00, "Long Entry");
    if (barNumberOfOrder==0)
    {
    barNumberOfOrder=CurrentBar;
    }
    if (CurrentBar>barNumberOfOrder && myEntryOrder!=null)
    {
    CancelOrder(myEntryOrder);
    Print("CancelOrder "+myEntryOrder.OrderState+" "+myEntryOrder);
    }
    }

    log:
    CancelOrder Accepted orderId='d9dcd959b40143dcbfa3c8ae3c15da65' account='Sim101' name='Long Entry' orderState=Accepted instrument='MNQ 06-21' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=13930 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=215 time='2021-04-23 14:21:18' gtd='2099-12-01' statementDate='2021-04-23'

    this code is only for test cancel order
    i test this code in real time, order has show in char and myEntryOrder is not null
    i want the order cancel in next bar, but it's not work.
    may i know what's wrong in those code?

    Thanks

    #2
    Welcome to the forums moneyexe!

    Please note that if you do not use an order method overload to specify IsLiveUntilCancelled, the orders will be cancelled on the next bar if the logic does not call them. You will also need to set IsLiveUntilCancelled to true in order to be able to use CancelOrder.

    Code:
    EnterLongMIT(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName)


    Testing the following works for me to see the cancelation.

    Code:
    private Order myEntryOrder;
    int barNumberOfOrder = 0;
    protected override void OnBarUpdate()
    {
        if (State == State.Historical)
            return;
    
        //if (Position.MarketPosition == MarketPosition.Flat)
            myEntryOrder=EnterLongMIT(0, true, 1, 13930.00, "Long Entry");
        if (barNumberOfOrder==0)
            barNumberOfOrder=CurrentBar;
        if (CurrentBar>barNumberOfOrder && myEntryOrder!=null)
        {
            CancelOrder(myEntryOrder);
            Print("CancelOrder "+myEntryOrder.OrderState+" "+myEntryOrder);
        }
    }
    An example that demonstrates using CancelOrder can also be found here - https://ninjatrader.com/support/help...thod_to_ca.htm

    We look forward to assisting.

    Comment


      #3
       thanks your reply. it work now.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X