Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help compiling "cancel an order not filled"

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

    Help compiling "cancel an order not filled"

    Good morning,
    Ihave a problem, i dont know how to compile (write the exact word) in order to cancel my not filled order. The words in red give me compiling errors. Can someone give me an answer or any advice? Thx

    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 = not Working)
    {
    CancelOrder(ShortStopLimit);
    }
    }

    #2
    Hi Ikerbar,

    Thank you for posting.

    You will need to create an IOrder to use the CancelOrder() effectively.

    You will need to create the variable in the variables region.
    Also, you will need to have null check in your condition and then submitting the order by defining the order for the IOrder Variable.

    Below is a link on how to use the CancelOrder() from the online help guide.
    http://www.ninjatrader.com/support/h...ancelorder.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Need condition to cancel order

      I have strategy. I need use cancel order but I want to cancel Order if price rises above High of bar which generated signal. I know how use CancelOrder with barNumberOfOrder.
      Part of my code:

      {myEntryOrder = EnterShortStop (0,true, 1, Math.Min (Open[0],Close[0]) -1 * TickSize, "Short");
      price3=High[0];
      else if (myEntryOrder != null && Close[0] > price3 )
      {CancelOrder(myEntryOrder);}
      As I understand Close[0] don't pertain. What I do need use in this example (instead last price) ? I use CalculateOnBarClose = true.
      I would be very grateful.

      Comment


        #4
        Kotyk,

        Thank you for your post.

        You can continue to use Close[0] but you will need to change the logic as it will never be higher than the High price of a bar, which is what you are checking in the condition.

        I would recommend changing the logic of the condition for the Close[0] against the High[0] price.

        Let me know if I can be of further assistance.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Cal View Post
          Kotyk,

          Thank you for your post.

          You can continue to use Close[0] but you will need to change the logic as it will never be higher than the High price of a bar, which is what you are checking in the condition.

          I would recommend changing the logic of the condition for the Close[0] against the High[0] price.

          Let me know if I can be of further assistance.
          I understand that logic is wrong. But I don't know how compare last price with the price when position was open.
          I set flag when position open "High[0]=price3" and then compare last price with price3.

          Comment


            #6
            Kotyk,

            Can you provide the code that sets the variable price3 and the full condition for it?
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              #region Variables

              private int p1 = 1;
              private int profitTarget = 50;
              private IOrder myEntryOrder = null;
              private double price2 = 0;
              private double price3 = 0;
              // User defined variables (add any user defined variables below)
              #endregion
              /// <summary>
              /// </summary>
              protected override void Initialize()
              {
              SetProfitTarget(CalculationMode.Ticks, ProfitTarget);
              Add(Bollinger(2, 14));
              CalculateOnBarClose = true;

              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              if ((ToTime(Time[0]) > 10000 && ToTime(Time[0]) < 50000))

              {
              // Condition set 1
              if (Low[0] <= Bollinger(2, 14).Lower[0]
              && Low[0] <=Low[1]
              … others conditions)
              {
              myEntryOrder = EnterLongStop (0,true, 1, Math.Max(Open[0],Close[0])+TickSize, "Long");
              price2=Low[0];
              SetStopLoss("", CalculationMode.Price, Low[0]-p1*TickSize,false);
              }
              else if (myEntryOrder != null && Close[0] < price2)
              {CancelOrder(myEntryOrder);}

              Comment


                #8
                Kotyk,

                Thank you for the code.

                It appears you are using unmanaged order entry for your script, however you do not have Unmanaged = true; in your initialize() method.

                I recommend putting this in and testing your script again.

                Let me know the results and if this helps
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Cal View Post
                  Kotyk,

                  Thank you for the code.

                  It appears you are using unmanaged order entry for your script, however you do not have Unmanaged = true; in your initialize() method.

                  I recommend putting this in and testing your script again.

                  Let me know the results and if this helps
                  Thanks. I understand that it must be unmanaged order but I need rewrite whole script fot it. example instead of EnterLongStop SubmitOrder.

                  Comment


                    #10
                    Kotyk,

                    Let's go back to the Price3 and Close[0].

                    You setup looks fine for setting the variable to the current High[0] price that you trying to get.

                    Are you not getting the condition to cancel the order called?
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Cal View Post
                      Kotyk,

                      Let's go back to the Price3 and Close[0].

                      You setup looks fine for setting the variable to the current High[0] price that you trying to get.

                      Are you not getting the condition to cancel the order called?
                      I don't understand. Price3 used for condition 2 for enter short positions. The code is the same.

                      Comment


                        #12
                        Kotyk,

                        You mentioned earlier that you were having issues with your condition using the price three and weren't sure about using the Close[0] price to test. Is this still the case?
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Cal View Post
                          Kotyk,

                          You mentioned earlier that you were having issues with your condition using the price three and weren't sure about using the Close[0] price to test. Is this still the case?
                          Yes. Ninja doesn't show mistake. But order cancelled on the next bar. liveUntilCancelled don't work.

                          Comment


                            #14
                            Kotyk,

                            Can you please attach the whole code so I can test the script on my end?

                            You will find the strategy in (My) Documents -> NinjaTrader 7 -> bin -> custom -> Strategy

                            To attach, you will need to click Reply -> Go Advanced -> Click the Paperclip in the top toolbar.

                            If you prefer you can send the script to me at support[at]ninjatrader[dot]com with ATTN Cal in the subject and reference this post in the body.
                            Cal H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            635 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            364 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            106 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            567 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            571 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X