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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X