Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitShort & CancelOrder

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

    ExitShort & CancelOrder

    when ExitShort or CancelOrder are called will an

    OnExecutionUpdate

    event be raised and ...

    for ExitShort what should I look for to determine a successful ExitShort?

    for CancelOrder will execution.Order.OrderState == OrderState.Accepted ?

    #2
    Hello delTick, and thank you for your question.

    The two methods you will need to use to check order status are OnOrderUpdate and OnExecution. I am providing help guide links for both.




    Originally posted by delTik
    when ExitShort or CancelOrder are called will an

    OnExecutionUpdate

    event be raised


    At every stage in the order process, OnOrderUpdate will be called. This is where you will want to check to see if your order has been filled or cancelled.

    Originally posted by delTik
    for ExitShort what should I look for to determine a successful ExitShort?
    When an Enter or Exit order is completed, you will see the OnExecution event raised.

    Originally posted by delTik
    for CancelOrder will execution.Order.OrderState == OrderState.Accepted ?
    When you attempt to cancel an order, an order in one of the states Cancelled, Filled, Rejected, or Unknown is a complete order.

    Here is a table with all the possible order states during OnOrderUpdate.

    Originally posted by http://ninjatrader.com/support/helpGuides/nt7/?iorder.htm
    OrderState.Accepted
    Order has been acknowledged by the broker
    OrderState.Cancelled
    Order has been cancelled
    OrderState.Filled
    Order has been filled
    OrderState.PartFilled
    Order has been part filled
    OrderState.PendingCancel
    An order cancellation request has been submitted
    OrderState.PendingChange
    An order change request has been submitted
    OrderState.PendingSubmit
    An order has been submitted
    OrderState.Rejected
    An order has been rejected
    OrderState.Working
    An order is working at the exchange
    OrderState.Unknown
    An unknown order state
    Please let us know if there is any other way we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      thank you.

      do these links also apply to NT8?

      this advises a different method of assigning an order object:



      [QUOTE]
      protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
      {
      // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
      // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not gauranteed to be complete if it is referenced immediately after submitting
      if (order.Name == "myEntryOrder" && orderState == OrderState.Filled)
      entryOrder = order;

      if (entryOrder != null && entryOrder == execution.Order)
      Print(execution.ToString());
      }
      [/QUOTE

      compared to:



      private IOrder entryOrder = null;

      protected override void OnBarUpdate()
      {
      if (entryOrder == null && Close[0] > Open[0])
      entryOrder = EnterLong();
      }

      protected override void OnExecution(IExecution execution)
      {
      if (entryOrder != null && entryOrder == execution.Order)
      Print(execution.ToString());
      }
      Last edited by delTik; 05-05-2016, 03:09 AM.

      Comment


        #4
        Thank you for pointing out where I misunderstood and answered this question for NinjaTrader 7. However, a lot of this applies directly to NinjaTrader 8 as well. If we examine the NT8 Help Guide documentation for CancelOrder as a starting point, we see two pages, one for the managed approach, and one for the unmanaged approach. The contents of the unmanaged approach CancelOrder simply link to CancelOrder for the managed approach. Inside the documentation for CancelOrder (Unmanaged), we find this (emphasis mine):

        Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/?managed_cancelorder.htm
        privateOrdermyEntryOrder=null;
        privateintbarNumberOfOrder=0;

        protectedoverridevoidOnBarUpdate()
        {
        // Submit an entry order at the low of a bar
        if(myEntryOrder==null)
        {
        // use 'live until canceled' limit order to prevent default managed order handling which would expire at end of bar
        EnterLongLimit(0,true,1,Low[0],"Long Entry");
        barNumberOfOrder=CurrentBar;
        }

        // If more than 5 bars has elapsed, cancel the entry order
        if(CurrentBar>barNumberOfOrder+5)
        CancelOrder(myEntryOrder);
        }

        protectedoverridevoidOnOrderUpdate(Orderorder,doublelimitPrice,doublestopPrice,intquantity,intfilled,
        doubleaverageFillPrice,OrderStateorderState,DateTimetime ,ErrorCodeerror,stringnativeError)
        {
        // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
        // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not gauranteed to be complete if it is referenced immediatelyaftersubmitting
        if(order.Name=="Long Entry"&&orderState==OrderState.Filled)
        entryOrder=order;


        // Checks for all updates to myEntryOrder.
        if(myEntryOrder!=null&&myEntryOrder==order)
        {
        // Check if myEntryOrder is cancelled.
        if(myEntryOrder.OrderState==OrderState.Cancelled)
        {
        // Reset myEntryOrder back to null
        myEntryOrder=null;
        }
        }
        }

        From this we can surmise that we use OnOrderUpdate and OnExecutionUpdate the same way we used OnOrderUpdate and OnExecution in NT7. You should continue using OnOrderUpdate to check for the status of an order you cancelled with CancelOrder, and you should be responding to filled trades in OnExecutionUpdate.

        I am including links to help guide documentation for OnOrderUpdate and OnExecutionUpdate for NT8, since these must be called differently in NT8.




        Please let us know if there is any other way we can help.
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Waxavi, 04-19-2024, 02:10 AM
        2 responses
        36 views
        0 likes
        Last Post poeds
        by poeds
         
        Started by chbruno, Yesterday, 04:10 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Max238, Today, 01:28 AM
        1 response
        23 views
        0 likes
        Last Post CactusMan  
        Started by giulyko00, Yesterday, 12:03 PM
        2 responses
        10 views
        0 likes
        Last Post giulyko00  
        Started by r68cervera, Today, 05:29 AM
        0 responses
        4 views
        0 likes
        Last Post r68cervera  
        Working...
        X