Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

limit order

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

    limit order

    I have a system where a trade entry is triggered and a limit buy order is placed at open of next bar + 4 tics. If the price retraces to a certain price I want to cancel the limit order. How would I code this?

    #2
    mballagan,

    To cancel orders you want to use CancelOrder() on the IOrder for the order. http://www.ninjatrader-support.com/H...ncelOrder.html
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      limit order

      Thanks for the info.

      If we look at the sample code:

      private IOrder myEntryOrder = null;
      private int barNumberOfOrder = 0;

      protected override void OnBarUpdate()
      {
      // Submit an entry order at the low of a bar

      if (myEntryOrder == null)
      {
      myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry");

      barNumberOfOrder = CurrentBar;
      }

      // If more than 5 bars has elapsed, cancel the entry order
      if (CurrentBar > barNumberOfOrder + 5)
      CancelOrder(myEntryOrder);
      }

      After the CancelOrder will myEntryOrder == null?

      Comment


        #4
        No. It will be in a PendingCancel or Cancelled state. You have to set it to null yourself (likely in OnOrderUpdate()).
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          limit order

          In the following code snippet I enter a longlimitorder:

          if(LongTrigger && CurrentBar == longorderbar)
          {
          LongOrder = EnterLongLimit(Open[
          0]+ TickSize*4,"LongEntry");
          SetStopLoss(
          "LongEntry",CalculationMode.Ticks,10,true);
          SetProfitTarget(
          "LongEntry",CalculationMode.Ticks,10);
          }

          If the price falls to a certain level I want to cancel the order if not filled is this the correct approach?

          if(Close[0] < pricelevel)
          {
          CancelOrder(LongOrder);
          }

          even if order not filled?

          Comment


            #6
            Note that your order will also auto cancel if you do not resubmit it on every single bar to keep it alive. Otherwise, yes it will cancel when your condition is met.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              limit order

              Would the following line check that the order had not been filled:

              LongOrder.OrderState != OrderState.Filled

              Is it a good idea to add this when cancelling an order that hasnt yet been filled, but could be accepted, working?

              Comment


                #8
                Before you can do any such check you need to check for null.

                Code:
                if (LongOrder != null && LongOrder.OrderState != OrderState.Filled && _____)
                    CancelOrder(LongOrder);
                You might as well check for OrderState != OrderState.Cancelled or PendingCancel too.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  limit order

                  I will put that into the code, thank you.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Dan_TUK, Today, 11:16 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by AlexanderHarrison, Today, 11:21 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post AlexanderHarrison  
                  Started by dmisselhorn, 07-02-2024, 07:50 AM
                  6 responses
                  46 views
                  0 likes
                  Last Post w5l8nx1
                  by w5l8nx1
                   
                  Started by spottysallrite, Today, 10:57 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by ghappy21, Yesterday, 10:32 AM
                  9 responses
                  60 views
                  0 likes
                  Last Post kasio811  
                  Working...
                  X