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

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
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by aligator, 01-06-2022, 12:14 PM
        2 responses
        223 views
        0 likes
        Last Post john_44573  
        Started by dmking, 11-12-2019, 12:31 PM
        4 responses
        4,140 views
        0 likes
        Last Post jasonw
        by jasonw
         
        Started by roblogic, Today, 04:31 PM
        0 responses
        9 views
        0 likes
        Last Post roblogic  
        Started by morrnel, 05-12-2024, 06:07 PM
        4 responses
        57 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by xepher101, 05-10-2024, 12:19 PM
        6 responses
        73 views
        0 likes
        Last Post xepher101  
        Working...
        X