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 rexsole, Today, 01:46 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post rexsole
                  by rexsole
                   
                  Started by dRun22, Today, 09:43 AM
                  3 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by HandsFreeTrader, 06-28-2023, 07:38 AM
                  4 responses
                  202 views
                  0 likes
                  Last Post uchauhan  
                  Started by gambcl, Today, 11:39 AM
                  2 responses
                  16 views
                  0 likes
                  Last Post gambcl
                  by gambcl
                   
                  Started by brucerobinson, Today, 12:14 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post brucerobinson  
                  Working...
                  X