• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry Orders cancelled after 5 minutes...

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

    Entry Orders cancelled after 5 minutes...

    Hi

    i run my strategy in a 5 minutes basis, i enter long or short with a limit order, calculateonbarclose=true

    i write the code to say, "if the order is not filled during the 5 minutes, keeps it but cancel it after the 3 bar if it is not filled (15 minutes in total)"

    but if the entry order is not filled after the 1st 5 minute, it is cancelled...

    here my code (as shown on the guide NT7), can you help to tell me what's wrong ?

    // Condition buy
    if ( entryOrderAchat == null && buycondition)

    {
    entryOrderAchat = EnterLongLimit(
    0, true, 1, Close[0], "Buy");
    barNumberOfOrderAchat = CurrentBar;
    }

    // If entryOrder has not been filled within 3 bars, cancel the order.
    elseif (entryOrderAchat != null && CurrentBar > barNumberOfOrderAchat + 3)
    {
    // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
    CancelOrder(entryOrderAchat);
    }

    #2
    Hi Thomas79,

    Code looks good from here for what you're looking to do. Is there any reason provided for cancelling this order in TraceOrders output? Enable it in Initialize() section and then check output in Tools > Output Window

    Try adding something like below to check if it's cancelling due to your custom logic or if it's something else:

    Code:
    else if (entryOrderAchat != null && CurrentBar > barNumberOfOrderAchat + 3)
    {
    Print("CB: " + CurrentBar);
    Print("BNO: " + barNumberOfOrderAchat);
    // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via
    EnterLong()
    CancelOrder(entryOrderAchat);
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      i recheck the code example... and i this i forget this part of code

      protectedoverridevoid OnOrderUpdate(IOrder order)
      {
      // Checks for all updates to entryOrder.
      if (entryOrder != null && entryOrder == order)
      {
      // Check if entryOrder is cancelled.
      if (order.OrderState == OrderState.Cancelled)
      {
      // Reset entryOrder back to null
      entryOrder = null;

      // Replace entry limit order with a market order.
      marketOrder = EnterLong(1, "market order");
      }
      }
      }

      Comment


        #4
        Hi, can you please help with programming "Cancel order" in NT Strategy? I have several condition sets in a Strategy and only for 1 of them I need to program Cancel order for a limit order (the other sets have market orders). So far I have:

        EnterLongLimit(0, true, DefaultQuantity, Close[0] + -2 * TickSize, "Long2v");

        Now the order is active till it is filled. I need to cancel this order after:
        1/ 20 minutes or 5 bars

        Can you please advise where and how to place the script for cancelling?

        Thanks a lot

        Comment


          #5
          Hi paatech,

          You can see a sample on CancelOrder() here:
          http://www.ninjatrader.com/support/f...ad.php?t=18890

          This sample cancels the order if not filled within 3 bars, so you should be able to adapt to your needs.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_RyanM View Post
            Hi paatech,

            You can see a sample on CancelOrder() here:
            http://www.ninjatrader.com/support/f...ad.php?t=18890

            This sample cancels the order if not filled within 3 bars, so you should be able to adapt to your needs.
            Thanks a lot, I trtied hard, but still have not managed to complete the set. Would you mind and completed the script for me? This would be great, many thanks. I need to cancel the order after 5 bars or 20 minutes. The condition set is:

            // Condition set 6 "Short 2v"
            if (CCI(14)[0] < 0
            && CCI(14)[1] < 0
            && CCI(50)[1] < 0
            && CCI(14)[1] > -100
            && CCI(50)[1] > -100
            && CCI(14)[2] < CCI(14)[1]
            && CCI(14)[0] < CCI(14)[1] + -5
            && CCI(50)[2] < CCI(50)[1]
            && CCI(50)[0] < CCI(50)[1] + -5
            && ToTime(Time[0]) >= ToTime(15, 40, 0)
            && ToTime(Time[0]) <= ToTime(18, 0, 0))
            {
            EnterShortLimit(0, true, DefaultQuantity, Close[0] + -2 * TickSize, "Short2v");
            }
            Last edited by paatech; 08-16-2012, 12:23 PM.

            Comment


              #7
              Unfortunately we are not able to custom code as it would limit our ability to provide support to everyone needing it. We're happy to help with any specific questions you have and if you would like professional custom coding development you can look into our 3rd party NinjaScript consultants here:

              http://www.ninjatrader.com/partners
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Cancelling IOrder with multiple instruments

                I have a functioning multi instrument strategy that I need to cancel any unfilled limit entry orders when the price has moved a set distance away from it. This is your standard IOrder script.... how do I incorporate the barsinprogress index to the private IOrder "myEntryOrder"?




                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);
                }


                Regards to all and thx
                Last edited by elliot5; 07-14-2015, 11:32 AM.

                Comment


                  #9
                  Hello everington_f,

                  How you would apply a BarsInProgress check depends on what you are trying to do. Could you please be more specific as to what you are trying to accomplish so we can better assist?

                  If you are submitting and checking the order against the primary data series it might look something like this:
                  Code:
                  private IOrder myEntryOrder = null;
                  private int barNumberOfOrder = 0;
                  
                  protected override void OnBarUpdate()
                  {
                      if(BarsInProgress==0) //If the primary data series is calling 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);
                      }
                  }
                  More information on using BarsInProgress can be found in our help guide here: http://ninjatrader.com/support/helpG...inprogress.htm

                  Thank you in advance.
                  Michael M.NinjaTrader Quality Assurance

                  Comment


                    #10
                    I have an array of 50 stocks and by entering longlimit get current bid I might find that the market moves away from my limit order and therefore needs to be cancelled. any working entry orders from that array need to be cancelled when the market moves 10 ticks away from the enterlimit level. Thats why i need barsinprogress incorporated into the IOrder to create the loop .

                    Comment


                      #11
                      Hello everington_f,

                      If you keep track of which orders are in which data series, then you know which orders to cancel when the condition is met. Here is an example using a List containing another List with IOrders. The first List is indexed by the BarsInProgress so we know which data series we are working with. The second List is indexed by the number of orders that data series contains:
                      Code:
                      #region Using declarations
                      //...
                      using System.Collections.Generic;
                      //...
                      #endregion
                      //...
                      #region Variables
                      	private List<List<IOrder>> orderList = new List<List<IOrder>>();
                      	private IOrder myEntryOrder = null;
                      	private int[] barNumberOfOrder;
                      #endregion
                      protected override void OnBarUpdate()
                      {
                      	if (orderList[BarsInProgress].Count == 0) //Only have one order per stock
                      	{
                      		orderList[BarsInProgress].Add(EnterLongLimit(0, true, 1, Low[0], "Long Entry"));
                      		barNumberOfOrder[BarsInProgress] = CurrentBar;
                      	}
                      	// If more than 5 bars has elapsed, cancel the entry order
                      	if (barNumberOfOrder[BarsInProgress] != null && CurrentBar > barNumberOfOrder[BarsInProgress] + 5)
                                  CancelOrder(orderList[BarsInProgress][0]); //Cancel the entry order
                      }
                      Please provide an example from your actual code if you would like a more specific example of what you are looking for.
                      Thank you in advance.
                      Michael M.NinjaTrader Quality Assurance

                      Comment


                        #12
                        I have taken your suggestion and have built it into the strategy. Many thanks for you help

                        Comment


                          #13
                          Hello everington_f,

                          Thank you for the update. I am glad to hear I could be of assistance.

                          Please let me know if you have any questions anytime.
                          Michael M.NinjaTrader Quality Assurance

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by tecmisc1, Today, 09:57 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post tecmisc1  
                          Started by mbesha, Today, 09:26 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post mbesha
                          by mbesha
                           
                          Started by Brillo, Today, 08:58 AM
                          0 responses
                          6 views
                          0 likes
                          Last Post Brillo
                          by Brillo
                           
                          Started by avrege, Today, 01:48 AM
                          2 responses
                          14 views
                          0 likes
                          Last Post avrege
                          by avrege
                           
                          Started by markbb10, Today, 07:14 AM
                          0 responses
                          7 views
                          0 likes
                          Last Post markbb10  
                          Working...
                          X