Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Canceling an Order

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

    Canceling an Order

    Hi,

    I've been looking through different strategies that people have posted and I ran across this code that I can't quite understand what's going on. Can anyone explain what this code does?

    private void CancelEntryOrder()
    {
    if (entryOrder == null) return;


    if (entryOrder.OrderState == OrderState.Filled) {
    if (entryOrder.IsLong)
    ExitLong();
    else
    ExitShort();
    }
    else {
    CancelOrder(entryOrder);
    }

    ResetState();
    }

    #2
    Hello Seastragg,

    Thanks for your post.

    This is custom code someone has written to close a position and cancel a pending entry order. The code is using Order objects to track the strategy's orders.

    To better understand this code, I would recommend viewing our SampleOnOrderUpdate strategy which demonstrates how Order objects can be used as well as how Order object assignment can be done with the OnOrderUpdate method.

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    Documentation for the NinjaScript methods that are in this snippet are linked below. (ResetState() is a custom method used in the snippet.)

    ExitLong() - https://ninjatrader.com/support/help.../?exitlong.htm
    ExitShort() - https://ninjatrader.com/support/help.../exitshort.htm
    CancelOrder() - https://ninjatrader.com/support/help...ancelorder.htm
    Order objects - https://ninjatrader.com/support/help.../nt8/order.htm

    For a more general overview on NinjaScript strategies, please see the Managed Approach documentation.

    Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

    Please let us know if we can be of further assistance.

    Comment


      #3
      Hi Jim,

      That sample is perfect! I'm looking through it now, thank you for the sample, this really helps!


      Cheers,
      Seastragg
      Last edited by Seastragg; 11-06-2019, 03:06 PM.

      Comment


        #4
        I have a followup question though. Which one is the one to close a position, and which one is to close a pending order?

        Cheers,
        Seastragg

        Comment


          #5
          Hello Seastragg,

          ExitLong and ExitShort close the position and cancel active entry orders. This is called in the snippet when entryOrder is filled.

          CancelOrder cancels entryOrder and is called when CancelEntryOrder is called and entryOrder is not filled.

          We look forward to assisting.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          89 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          135 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          119 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          69 views
          0 likes
          Last Post PaulMohn  
          Working...
          X