Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder if no fill

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

    CancelOrder if no fill

    I use the unmanaged mode:
    Sometimes the price passes over a limit order and there is no filling and I want to automate the cancellation process.
    I use the unmanaged mode template of the ninjatrader developers of this forum.
    This is the command:
    if (longEntry == null)
    longEntry = SubmitOrderUnmanaged(0,OrderAction.Buy,OrderType.L imit,1, GetCurrentAsk(), 0, oco, "long limit entry");

    the price assigned to LimitPrice appears in the oputput window of ninjascript
    but in the compilation it does not support "LimitPrice" as a valid value
    I have thought about:
    if (longEntry == null && shortEntry == null && Position.AveragePrice >= LimitPrice )
    {
    CancelAll();
    }

    I would appreciate a solution to cancel orders that are not filled.

    thank you.

    #2
    Hello franki,

    Thank you for your post.

    The limit price of an order cannot just be accessed by using LimitPrice. You would want to assign your order object to a variable as you can see in the attached example script. You can then access the limit price with myOrder.LimitPrice (where myOrder is the variable name you've assigned the order to).

    Then, in OnBarUpdate(), let's say I want to cancel the order if the limit price gets passed over without filling.

    protected override void OnBarUpdate()
    {
    if(myOrder != null && Close[0] > myOrder.LimitPrice)
    CancelOrder(myOrder);

    }

    Here is some documentation from our help guide on the Unmanaged approach as I would highly suggest reviewing the necessary structure:



    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Hi NinjaTrader_Kate !!!

      In theory those variable objects already exist ...

      #region Variables
      private Order shortEntry = null;
      private Order longEntry = null;

      it would be as easy as ...
      if (Close [0] <longEntry.LimitPrice || Close [0]> shortEntry.LimitPrice)




      If so, I appreciate your help.
      Thank you!

      Comment


        #4
        Hello franki,

        Thank you for your reply.

        That's not quite correct. You still have to assign the current orders to those variables before you can use them in your comparison. In the case of the example above, that's done in the AssignOrderToVariable() method:

        Code:
                private void AssignOrderToVariable(ref Order order)
                {
                    if (order.Name == "longStopEntry" && longStopEntry != order)
                        longStopEntry = order;
        
                    if (order.Name == "shortStopEntry" && shortStopEntry != order)
                        shortStopEntry = order;
                }
        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        89 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        152 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        80 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        53 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        63 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X