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

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.
    JimNinjaTrader Customer Service

    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.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          23 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          22 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X