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 DayTradingDEMON, Yesterday, 08:54 AM
                  13 responses
                  41 views
                  0 likes
                  Last Post DayTradingDEMON  
                  Started by DJ888, Yesterday, 05:57 PM
                  2 responses
                  20 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by mtamaku, Today, 05:21 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post mtamaku
                  by mtamaku
                   
                  Started by rbeckmann05, Yesterday, 11:37 PM
                  2 responses
                  13 views
                  0 likes
                  Last Post rbeckmann05  
                  Started by reekotubbs, Today, 01:09 PM
                  1 response
                  19 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Working...
                  X