Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit orders open

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

    Limit orders open

    I want to cancel my limit orders with CancelOrder() command but want to validate first what orders are pending. How can I check the open (not yet executed) limit orders?
    What is default duration of limit orders if I do not exit at close?

    #2
    Hello PaulZ,

    Thank you for your note.

    To check these you will need to save the order to an IOrder. This will also be needed to use CancelOrder().

    With the IOrder you can check the state of the order.

    For example:
    In #region Variables
    private IOrder myOrder = null;

    In OnBarUpdate():
    myOrder = EnterLongLimit(1, Low[0]-10*TickSize);

    Where ever you are about to cancel the order:
    if (myOrder.OrderState == OrderState.Accepted || myOrder.OrderState == OrderState.Working)
    CancelOrder(myOrder);

    Below is a link to the help guide on IOrder.
    http://www.ninjatrader.com/support/h...nt7/iorder.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      Thank you for your suggestion. I found that I first need to add a filter:
      if (MyOrder != null)
      before the statement
      if (myOrder.OrderState == OrderState.Accepted || myOrder.OrderState == OrderState.Working)
      as MyOrder.OrderState gives an error for null.
      Is that correct or am I missing something?

      Further, if I do not cancel my order and do not exit at the close, how long will my limit order stay pending?

      Comment


        #4
        Hello,

        Thank you for the question.

        Yes you would need to check that the order is not null, in the chance that is is null it would have an error if you tried to check the order state of a null IOrder.

        in general checking for null is a good idea when working with objects, in the help guide examples for OnExecution and OnMarketData you can see null orders are checked for as well.

        I look forward to being of further assistance.

        Comment


          #5
          Thanks for your response.
          My orders get cancelled without a CancelOrder() statement being triggered (after the first bar following the EnterShortLimit() command).
          What cause can trigger an order cancellation, other than my CancelOrder() command?

          Comment


            #6
            Hello,

            Thank you for the question.

            I wanted to check, on the order that was canceled after 1 bar, was this order submitted by a condition that only was true for 1 bar and then was no longer true?

            If the order is not set LiveUntilCanceled = true, the order would last 1 bar and then cancel unless the condition that placed the order remained true or if there was another condition to re submit the order to keep it alive.

            Can you please see if this is the case, if not can you provide some of the logic you are using for the order entry?

            I look forward to being of further assistance.

            Comment


              #7
              The order is placed through the following command:
              MyOrder = EnterShortLimit(OrderSize, TargetEntry, Convert.ToString(TradeCount));
              where int OrderSize, double TargetEntry and int TradeCount received a value.

              Comment


                #8
                Hello,

                Thank you for the reply.

                Was the condition that created this order still true on the next bar? If not I would suspect this got canceled because of that.

                If the overall condition that you have this statement in is only true on 1 bar, the order would be submitted but not kept alive if the condition is no longer true on the next bar.

                A working order would not be persisted across multiple bars unless it is either set to do so using LiveUntilCanceled, or if the condition that created it remains true so it can call the order method on each OnBarUpdate using the signal name to update the existing order.

                I look forward to being of further assistance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                633 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                364 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                567 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                568 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X