• 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

How to cancel buy order if limited price is jumped

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

    How to cancel buy order if limited price is jumped

    I would like how to compile this condition:

    If actual ask price is bigger than my actual limited buy order price (because it has been a big volatility in the market and the order has not been filled) close long order.

    Thank you very much.

    #2
    Hello ikerbar,

    Thank you for your post.

    You will need to IOrder objects for the orders so that you can call CancelOrder() to cancel the order based on your condition.

    For information on CancelOrder() please visit the following link: http://www.ninjatrader.com/support/h...ancelorder.htm

    For information on IOrder objects please visit the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm

    Then using GetCurrentAsk() you can check the current ask value against the price of the IOrder object:
    Code:
    			if(GetCurrentAsk(0) >= myOrder.LimitPrice)
    			{
    				CancelOrder(myOrder);
    			}
    For information on GetCurrentAsk() please visit the following link: http://www.ninjatrader.com/support/h...currentask.htm

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      I have a problem, i dont know how to compile (write the exact word) in order to cancel my running order. The words in red give me compiling errors.

      My compilation for a short order:

      {
      // Condition set 1
      if (ToTime(DateTime.Now) >= ToTime ( 10, 29, 57) && ToTime(DateTime.Now) <= ToTime ( 10, 29, 58))
      {
      EnterShortStopLimit( 1, GetCurrentBid() - 11 * TickSize, GetCurrentBid() - 5 * TickSize, "corto")
      }
      // Condition set 2 "if the price currentbid jump my limitprice and the order has not been filled, cancel the order"
      if (ToTime(DateTime.Now) >= ToTime ( 10, 29, 59) && GetCurrentBid() < ShortStopLimit.LimitPrice && OrderStatus is not Working)
      {
      CancelOrder(ShortStopLimit);
      }
      }
      Last edited by ikerbar; 09-18-2013, 04:02 AM.

      Comment


        #4
        Hello ikerbar,

        Thank you for your post.

        Below you will find how to properly add an IOrder object and call that IOrder object to cancel an order:
        Code:
        #region Variables		
                private IOrder myOrder;
                #endregion
        		
        		protected override void OnBarUpdate()
        		{
        // Condition set 1
        if (ToTime(DateTime.Now) >= ToTime ( 10, 29, 57) && ToTime(DateTime.Now) <= ToTime ( 10, 29, 58))
        {
        myOrder = EnterShortStopLimit( 1, GetCurrentBid() - 11 * TickSize, GetCurrentBid() - 5 * TickSize, "corto");
        }
        // Condition set 2 "if the price currentbid jump my limitprice and the order has not been filled, cancel the order"
        if (ToTime(DateTime.Now) >= ToTime ( 10, 29, 59) && ...)
        {
        CancelOrder(myOrder);
        }
        I recommend reviewing the information on IOrder at the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm

        Please let me know if I may be of further assistance.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Thank you very much,
          last question about it (sorry of been a noob)

          if i want to cancel the order if the order hasnt been filled can i write this?

          if (myOrder.OrderState != OrderState.Filled)

          CancelOrder (myOrder)

          Thanks in advance

          Comment


            #6
            Hello ikerbar,

            Thank you for your response.

            That is the correct way to check if the order has not filled.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Hi again,
              after using my programed strategy, the order didnt cancel when it was not filled. What am i missing? Thanx in advance.

              My compiled strategy:

              #region Using declarations
              using System;
              using System.ComponentModel;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Data;
              using NinjaTrader.Indicator;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Strategy;
              #endregion

              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
              /// <summary>
              /// Enter the description of your strategy here
              /// </summary>
              [Description("Enter the description of your strategy here")]
              public class GasBajadaCancel21 : Strategy
              {
              #region Variables
              // Wizard generated variables
              private int ordenes = 1; // Default setting for Ordenes
              private int stop = 20; // Default setting for Stop
              // User defined variables (add any user defined variables below)
              private IOrder myOrder1;
              #endregion

              /// <summary>
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              /// </summary>
              protected override void Initialize()
              {
              SetProfitTarget("", CalculationMode.Ticks, 60);
              SetTrailStop("", CalculationMode.Ticks, 20, false);

              CalculateOnBarClose = false;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnMarketData(MarketDataEventArgs e)

              {
              // Condition set 1
              if (ToTime(DateTime.Now) >= ToTime ( 16, 29, 57) && ToTime(DateTime.Now) <= ToTime ( 16, 29, 58))
              {
              myOrder1 = EnterShortStopLimit( 1, GetCurrentBid() - 31 * TickSize, GetCurrentBid() - 21 * TickSize, "corto");
              DrawTextFixed("My text (fixed)" + CurrentBar, "Bajada", TextPosition.TopLeft);
              }
              // Condition set 2
              if ((ToTime(DateTime.Now) >= ToTime ( 16, 29, 59)) && (GetCurrentBid() < myOrder1.LimitPrice) && (myOrder1.OrderState != OrderState.Filled))
              {
              CancelOrder(myOrder1);
              }
              }
              #region Properties
              [Description("")]
              [GridCategory("Parameters")]
              public int Ordenes
              {
              get { return ordenes; }
              set { ordenes = Math.Max(1, value); }
              }

              [Description("")]
              [GridCategory("Parameters")]
              public int Stop
              {
              get { return stop; }
              set { stop = Math.Max(1, value); }
              }
              #endregion
              }
              }

              Comment


                #8
                Hello ikerbar,

                Thank you for your post.

                In your code I do not see a check for null on the IOrder object before calling it's order state. Try adding the following:
                Code:
                if (myOrder1 != null && (ToTime(DateTime.Now) >= ToTime ( 16, 29, 59)) && (GetCurrentBid() < myOrder1.LimitPrice) && (myOrder1.OrderState != OrderState.Filled))
                {
                CancelOrder(myOrder1);
                myOrder1 = null;
                }
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ikerbar,

                  Thank you for your response.

                  Please attach your strategy to your response so I may investigate this matter further. You can find your strategy by going to the following directory on your PC: (My) Documents\NinjaTrader 7\bin\Custom\Strategy > it will be a .cs file.
                  Patrick H.NinjaTrader Customer Service

                  Comment


                    #10
                    Sorry i found the error by myself. I forgot to put the &&
                    Thank you very much for your help!!

                    Comment


                      #11
                      Good evening Patrick,
                      i have done a simulated trade to check it, but i have another problem. The trailing stop doesnt work. The trailing stop continue all the time in the first stop price and doesnt follow the price move with the profit.

                      Comment


                        #12
                        Hello ikerbar,

                        Thank you for your response.

                        What method is used for your trailing stop? Are you using SetTrailStop()? Can you provide the code used for the trailing stop?

                        I look forward to your response.
                        Patrick H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by vhjscv, Yesterday, 10:31 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post vhjscv
                        by vhjscv
                         
                        Started by buick, Yesterday, 09:37 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post buick
                        by buick
                         
                        Started by Hagar, Yesterday, 07:12 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post Hagar
                        by Hagar
                         
                        Started by jtrading82, Yesterday, 01:55 PM
                        4 responses
                        28 views
                        0 likes
                        Last Post bppayne
                        by bppayne
                         
                        Started by Hagar, Yesterday, 06:52 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post Hagar
                        by Hagar
                         
                        Working...
                        X