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 ScottW, Today, 06:09 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ScottWalsh, Today, 06:52 PM
        0 responses
        4 views
        0 likes
        Last Post ScottWalsh  
        Started by ftsc2022, 10-25-2022, 12:03 PM
        5 responses
        256 views
        0 likes
        Last Post KeyonMatthews  
        Started by Board game geek, 10-29-2023, 12:00 PM
        14 responses
        244 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Waxavi, 04-19-2024, 02:10 AM
        4 responses
        56 views
        0 likes
        Last Post sonia0101  
        Working...
        X