Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder() doesn't work

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

    CancelOrder() doesn't work

    Hello,

    I have the code below that creates a order but the cancellation of this order is not done :

    private Order myEntryOrder = null;

    protected override void OnMarketDepth(MarketDepthEventArgs e)
    {

    myEntryOrder = EnterLongLimit(1, e.Price, "orederachat");
    CancelOrder(myEntryOrder);
    }

    Thank you for your help​

    #2
    Hello scalping_Strategy,

    That won't work for a few reasons. The first reason is that you can't do an action like submitting an order and cancelling an order all at once, the order won't even be submitted before you try to cancel it. The second reason is that you need to make the order live until cancelled so it can be cancelled.

    To be able to cancel the order it needs to be accepted or working so you would need the CancelOrder to be called at a later time based on some condition.

    There is a sample showing how to cancel an order here: https://ninjatrader.com/support/help...thod_to_ca.htm

    Comment


      #3
      Hello,

      Thank you for you answer.
      I just made a summary but my complete code is this:

      private Order myEntryOrder = null;

      protected override void OnMarketDepth(MarketDepthEventArgs e)
      {
      rows = e.Instrument.MarketDepth.Bid;
      ​var top30Rows = rows.Take(30);
      foreach (var row in top30Rows)
      {
      if (row.Volume > 7 * averageVolume)
      {
      myEntryOrder = EnterLongLimit(1, row.Price, "orederachat");
      SetStopLoss(CalculationMode.Ticks, StopLossTicks);
      SetProfitTarget(CalculationMode.Ticks, 2);​
      }

      else
      {
      Print("Order closed");​
      CancelOrder(myEntryOrder);
      }​
      }​

      I have a limit order created but it is not closed and I have "Order closed" which is displayed in the log but the order is not closed

      Comment


        #4
        Hello scalping_Strategy,

        Please see the sample linked in the last post, that goes over how to cancel an order and how the order needs to be submitted as live until cancelled.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        131 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X