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 NullPointStrategies, Today, 05:17 AM
      0 responses
      44 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      65 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X