Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    JesseNinjaTrader Customer Service

    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.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by The_Sec, Yesterday, 03:37 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by vecnopus, Today, 06:15 AM
        0 responses
        1 view
        0 likes
        Last Post vecnopus  
        Started by Aviram Y, Today, 05:29 AM
        0 responses
        5 views
        0 likes
        Last Post Aviram Y  
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        36 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X