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() unmanaged approach

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

    CancelOrder() unmanaged approach

    Hi All:

    In my strategy I use an unmanaged approach to check if my order has been filled and to limit the number of trades per bar. Below is a snippet..

    private IOrder entryOrder = null;

    protected override void OnBarUpdate()

    {

    entryOrder = EnterLongLimit(0, true, DefaultQuantity, bidPrice, "MyStrategyOrder");

    }

    protected override void OnExecution(IExecution execution)
    {

    // Check if Order is Filled or Partially Filled
    if (entryOrder != null && entryOrder == execution.Order)
    {
    thisBarTrades++;
    }


    If this working order is not filled, I would like to cancel the order after X amount of bars. I viewed examples of cancelling orders in the MANAGED APPROACH, but how does one cancel a working order in an unmanaged approach?

    Thanks in advance

    #2
    geekodude, it would be the same as in managed, using the IOrder you wish to cancel in the dedicated CancelOrder() method. In your snippet you are in managed still, with your Enter() method call. Unmanaged would be using the SubmitOrder method then for trade entry.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand, thanks for the quick reply.

      After literally sleeping on this problem last night, the solution is to define & set these variables:

      private IOrder entryOrder = null;
      private IOrder MyCancelOrder = null;

      protected override void OnBarUpdate()

      {

      entryOrder = EnterLongLimit(0, true, DefaultQuantity, bidPrice, "MyStrategyOrder");
      MyCancelOrder = entryOrder;

      }

      And from the documentation Ninjatrader provides on how to cancel an order after X amount of bars in the Managed Approach here



      I was able to cancel an existing order in OnBarUpdate() and limit the number of trades per bar using OnExecution(IExecution execution)

      WOW!
      Last edited by geekodude; 04-24-2014, 10:31 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      192 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,235 views
      0 likes
      Last Post xiinteractive  
      Working...
      X