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 cre8able, 02-11-2023, 05:43 PM
      3 responses
      236 views
      0 likes
      Last Post rhubear
      by rhubear
       
      Started by frslvr, 04-11-2024, 07:26 AM
      8 responses
      113 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by stafe, 04-15-2024, 08:34 PM
      10 responses
      46 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by rocketman7, Today, 09:41 AM
      3 responses
      11 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by traderqz, Today, 09:44 AM
      2 responses
      10 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X