Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issues with limit orders...

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

    #16
    For sure you will keep resubmitting. Your reset flag condition is when you are flat. That is not a good stand alone condition. It can take many bars for your limit orders to fill and the whole time they are working, you are flat. You should not reset your orders till after your entries fill/cancel/etc.
    Josh P.NinjaTrader Customer Service

    Comment


      #17
      in order to track if the orders are filled or cancelled, would I have to do this using IOrder? or is there some other method?

      really appreciate the help, else i think i'll be bald by days end from pulling my hair out!

      Comment


        #18
        IOrder would probably be the cleanest way. Another way could be maybe trying to use BarsSinceEntry() mixed with tracking of position direction changes.
        Josh P.NinjaTrader Customer Service

        Comment


          #19
          essentially what I want to do is if the price has moved 4 ticks in the opposite direction of my first limit order, I want to only then resubmit

          Comment


            #20
            BigDog008,

            Keep the flag and resubmit only when you want to. You need to program the conditions to do what you want.
            Josh P.NinjaTrader Customer Service

            Comment


              #21
              still having problems... here is the code I am using to test my logic... I'm not able to seem to have orders submitted unless I set the number of bars to cancel on to be some large number say 20.... please help...

              Code:
                  {
                      #region Variables
                      // Wizard generated variables
                      private int period = 1; // Default setting for Length
                      private IOrder myEntryOrder = null;
                      private int barNumberofOrder = 0;
                      // User defined variables (add any user defined variables below)
                      #endregion
              
                      protected override void Initialize()
                      {
                          CalculateOnBarClose = false;
                      }
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                          // GET INDICATOR VALUES TO ENTER BUY MODE OR SELL MODE
                          
                          // SELL MODE
                          if (High[0] < EMA(Period)[0]
                              && myEntryOrder == null)
                          {
                              myEntryOrder = EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 4 * TickSize, "Short");
                              barNumberofOrder = CurrentBar;
                          }            
                          // BUY MODE
                          if (Low[0] > EMA(Period)[0]
                              && myEntryOrder == null)
                          {
                              myEntryOrder = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() + -4 * TickSize, "Long");
                              barNumberofOrder = CurrentBar;
                          }            
                          // CANCEL ORDERS
                          if (CurrentBar > barNumberofOrder + 5)
                          {
                              CancelOrder(myEntryOrder);
                              myEntryOrder = null;
                          }
                      }    
                                
                          // WORK ORDERS, CANCEL ORDERS, STOP LOSS, PROFIT TARGETS
                          protected override void OnOrderUpdate(IOrder order)
                          {
                              if (myEntryOrder != null && myEntryOrder.Token == order.Token)
                              {
                                  Print(order.ToString());
                                  if (order.OrderState == OrderState.Working
                                      && CurrentBar > barNumberofOrder + 5)
                                  {
                                      myEntryOrder = null;
                                      CancelOrder(myEntryOrder);
                                  }                    
                                  if (order.OrderState == OrderState.Filled)                   
                                  {
                                      SetStopLoss("Long", CalculationMode.Ticks, 8, false);
                                         SetStopLoss("Short", CalculationMode.Ticks, 8, false);
                          
                                      SetProfitTarget("Long", CalculationMode.Ticks, 8);
                                      SetProfitTarget("Short", CalculationMode.Ticks, 8);
                                      
                                      myEntryOrder = null;
                                  }                    
                              }
                          }
                     
                      #region Properties
                      [Description("")]
                      [Category("Parameters")]
                      public int Period
                      {
                          get { return period; }
                          set { period = Math.Max(1, value); }
                      }
                      #endregion
              the reason I put in a Cancel Orders section in the OnBarUpdate() and in OnOrderUpdate() was because I could not seem to get it the model to NOT keep resubmitting prices constantly, but by doing this... I could.... I'm making some progress, but yet quite confused and would really appreciate the help
              Last edited by BigDog008; 06-08-2009, 12:46 AM.

              Comment


                #22
                BigDog008,

                I am not quite sure what you mean by resubmitting prices constantly. Your entry orders will go in when the IOrder is null. Once it is accepted it will not be possible to resubmit until the IOrder is reset back to null. Not sure how you have concluded you cannot cancel in less bars. I suggest you add Print() in your code and try to follow it each step of the way and see what it is evaluating your conditions as.
                Josh P.NinjaTrader Customer Service

                Comment


                  #23
                  Josh, sorry about the incoherent post... was up late at night when I started typing :P

                  what i ment by constantly resubmitting is that say an order is working, and then filled with its appropriate stop and target in place... once either the stop or target is hit, and the proper condition is met, it should submit a new order, which it doesn't seem to do....

                  i've attached the code to show what I mean... I think that would explain better what I'm trying to do or the issues i'm having... i'm trying to run it on 6Range bar on say the ES contract... as far as cancelling orders... you'll notice when you run if you want to cancel orders in say 3 bars vs 5... it doesn't seem to do it, which I find confusing because the logic seems sound...
                  Attached Files

                  Comment


                    #24
                    BigDog008,

                    If you want it to submit a new order after you have closed your current trade you will want to reset your IOrder after the trade has closed.

                    You will need to debug why your cancels aren't working. Please use TraceOrders = true and add Print()s to see what is happening.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #25
                      Originally posted by NinjaTrader_Josh View Post
                      BigDog008,

                      If you want it to submit a new order after you have closed your current trade you will want to reset your IOrder after the trade has closed.

                      You will need to debug why your cancels aren't working. Please use TraceOrders = true and add Print()s to see what is happening.
                      that's what I was doing in the OnOrderUpdate section...


                      once an order is considered working... i reset it to null... also once its filled i set it to null.... do i have to do this when the targets or losses are hit too?

                      Comment


                        #26
                        What I was suggesting was for you not to reset at that point but rather only reset after the trade completes; as in gets in and out. When you reset it at the point where you place stop/targets you are opening up your strategy for further trades at that point in time (provided EntriesPerDirection allows you to). Not sure if that is what you intend or not. Your call.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Josh,

                          Rather than using the CancelOrder function based on number of bars passed, is it possible to use it based on number ticks the current price has deviated from the limit order?

                          also do I need to handle CANCEL ORDERS in the OnBarUpdate() section, or can I use that to simply enter BUY MODE and SELL MODE, and then manage the working and filled orders stictly from OnOrderUpdate()

                          Comment


                            #28
                            You can use whatever you want. Just program an if-statement that checks price versus your limit price and then call CancelOrder when you see fit.

                            Not following what you mean by BUY MODE and SELL MODE. CancelOrder() cancels the order you tell it to cancel. It doesn't do anything else. You can call it from where ever you want.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #29
                              ok sounds good...

                              also can the Token functions be used in the OnBarUpdate section? or only on OnOrderUpdate...

                              for example...

                              Code:
                              if (myEntryOrder != null && myEntryOrder.Token == order.Token)

                              Comment


                                #30
                                Can be used anywhere you need them.
                                Josh P.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by argusthome, Yesterday, 10:06 AM
                                0 responses
                                17 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                16 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                14 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                9 views
                                0 likes
                                Last Post TheRealMorford  
                                Started by Mindset, 02-28-2026, 06:16 AM
                                0 responses
                                38 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X