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 NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          55 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          132 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X