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

Is there a way to handle Order Cancelled?

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

    Is there a way to handle Order Cancelled?

    Hello,

    I could not find an Order.State == Cancelled. When I run my strategy, at times, the order is cancelled and an entry opportunity is missed.

    Qs:
    1. What would cause this? The entry price is 2 ticks above the last price (long). The profit target is 4 ticks away, and stop loss is 8 ticks away. So none of them are too close to the entry price to collide.
    2. I notice also NT says order is cancelled when in fact it has reached the profit target. It doesn't say Target Filled, but rather Cancelled, even so the position is filled and closed at the profit target.

    I would like to handle the case where an order is cancelled and an entry is missed. Would be good to know why, but more important is I'd like to resubmit the order. Is it due to the price has moved to another bar?

    Many Thanks, Caesar.

    #2
    Hello Caesar,

    Where you have asked:
    What would cause this?
    What are you referring to by 'this'?
    Are you asking why the order cancellation did not trigger OnOrderUpdate() with OrderState.Cancelled?

    Are you asking why the order was cancelled?
    Are you cancelling the order with CancelOrder()?
    Is this the managed approach and the order is being automatically cancelled due to liveUntilCancelled false, as shown the TraceOrders messages?
    Is the order an OCO order and the opposing order filled?

    If an order submitted by a strategy was cancelled and did not trigger OnOrderUpdate() with OrderState.Cancelled, I will need to see evidence of this. Please provide a reduced test script that can produce the behavior, has TraceOrders enabled, and prints the order.OrderState in OnOrderUpdate().

    I notice also NT says order is cancelled when in fact it has reached the profit target. It doesn't say Target Filled, but rather Cancelled, even so the position is filled and closed at the profit target.
    Are you certain this is same order with the same ID?
    Are you printing the order object in OnOrderUpdate showing the ID of the order?
    No other order was filled to exit the position? (Perhaps an OCO order?)

    I would like to handle the case where an order is cancelled and an entry is missed.
    This is done in OnOrderUpdate() by checking the order.OrderState == OrderState.Cancelled.
    The help guide has sample code of checking an orders orderstate.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Caesar,

      Where you have asked:

      What are you referring to by 'this'?
      Are you asking why the order cancellation did not trigger OnOrderUpdate() with OrderState.Cancelled?
      Yes, I just found it.Thanks.

      Originally posted by NinjaTrader_ChelseaB View Post
      Are you asking why the order was cancelled?
      Are you cancelling the order with CancelOrder()?
      The order is cancelled by the system.
      Yes, there doesn't seem to be any reason for the cancellation.

      Originally posted by NinjaTrader_ChelseaB View Post
      Is this the managed approach and the order is being automatically cancelled due to liveUntilCancelled false, as shown the TraceOrders messages?
      I don't know anything about liveUntilCancelled, what is the default behaviour?
      The order was submitted by EnterLongLimit.

      Originally posted by NinjaTrader_ChelseaB View Post
      Is the order an OCO order and the opposing order filled?
      [/quote/

      No, just a simple EnterLong/Short.

      Originally posted by NinjaTrader_ChelseaB View Post
      If an order submitted by a strategy was cancelled and did not trigger OnOrderUpdate() with OrderState.Cancelled, I will need to see evidence of this. Please provide a reduced test script that can produce the behavior, has TraceOrders enabled, and prints the order.OrderState in OnOrderUpdate().


      Are you certain this is same order with the same ID?
      Are you printing the order object in OnOrderUpdate showing the ID of the order?
      No other order was filled to exit the position? (Perhaps an OCO order?)


      This is done in OnOrderUpdate() by checking the order.OrderState == OrderState.Cancelled.
      The help guide has sample code of checking an orders orderstate.
      https://ninjatrader.com/support/help...rderupdate.htm
      As I wasn't aware of OrderState.Cancelled, I'll have to code this up.

      Many Thanks Chelsea!

      Comment


        #4
        Hello Caesar,

        To confirm, you have enabled TraceOrders?
        What is the message from TraceOrders when the order is cancelled?

        EnterLongLimit() would be using the managed approach and would be automatically cancelled if isLiveUntilCancelled is not set to true.

        EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)
        EnterLongLimit(0, true, 1, Low[0] - 3 * TickSize, "myLimitEntry");

        "Parameters
        isLiveUntilCancelled The order will NOT expire at the end of a bar, but instead remain live until the CancelOrder() method is called or its time in force is reached.​"
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          No, I have not enabled TraceOrder, something new for me to learn, I'm very much a novice with NT8. So far it's been great, I like the preciseness of C#.

          Many Thanks for the TraceOrders tip, Caesar.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Brevo, Today, 01:45 AM
          0 responses
          6 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          3 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          384 views
          1 like
          Last Post Gavini
          by Gavini
           
          Started by oviejo, Today, 12:28 AM
          0 responses
          6 views
          0 likes
          Last Post oviejo
          by oviejo
           
          Working...
          X