Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit Orders still behaving badly...

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

    Limit Orders still behaving badly...

    I'm still wrestling with limit orders, and am still having issues in getting the model to send orders when I have my cancellation logic in place... I've tried doing TraceOrders = true; along with Print() statements but am stuck... this is the follwing info I get at the Output screen....

    PHP Code:
    Order='NT-00000/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=944.25 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='14bc74ceed314544bcba8a89a9afba29' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00000/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=944.25 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=944.25 Token='14bc74ceed314544bcba8a89a9afba29' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00003/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=941 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='864e51fabf144f35aa368b4d695a5354' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00003/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=941 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='864e51fabf144f35aa368b4d695a5354' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00003/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=941 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=941 Token='864e51fabf144f35aa368b4d695a5354' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00006/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=941.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='1d848f0a5f394e4a9b955774d2d5e076' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00006/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=941.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=941.75 Token='1d848f0a5f394e4a9b955774d2d5e076' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00009/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=939 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='17f8b78fc6db4c34a4d90f2ddfc8007a' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00009/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=939 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=939 Token='17f8b78fc6db4c34a4d90f2ddfc8007a' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00012/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=938.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='51cc9f4bc34b4859ad9ca1796d016764' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00012/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=938.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='51cc9f4bc34b4859ad9ca1796d016764' Gtd='12/1/2099 12:00:00 AM' 
    
    Now what's odd about this is that I want to run my model only from 8:30 am to 10:00 am Chicago time.... these orders are going out the moment I push Start on the strategies tab, even when its before 8:30 am on the Market Replay bar...

    This is the logic I am using... Orders Per Direction is only 1 for now....

    Code:
            {
                // Condition set 1
                if (High[0] > EMA(Period)[0]
                    && entryOrder == null)
                {
                    entryOrder = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() + -2 * TickSize, "Long");
                }
    
                // Condition set 2
                if (Low[0] < EMA(Period)[0]
                    && entryOrder == null)
                {
                    entryOrder = EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 2 * TickSize, "Short");
                }
                
                if (entryOrder != null)
                {
                    Print(entryOrder.ToString());
                    
                    if (entryOrder.OrderState == OrderState.Working
                        && entryOrder.Action == Action.Buy
                        && GetCurrentBid() >= entryOrder.LimitPrice + 4 * TickSize)
                    
                    {
                        CancelOrder(entryOrder);
                        entryOrder = null;
                    }
                    
                    if (entryOrder.OrderState == OrderState.Working
                        && entryOrder.Action == Action.SellShort
                        && GetCurrentAsk() <= entryOrder.LimitPrice - 4 * TickSize)
                    
                    {
                        CancelOrder(entryOrder);
                        entryOrder = null;
                    }
                    
                    if (entryOrder.OrderState == OrderState.Filled
                        && entryOrder.Action == Action.Buy)
                    {
                        SetProfitTarget("Long", CalculationMode.Ticks, 8);
                        SetStopLoss("Long", CalculationMode.Ticks, 6, false);
                        entryOrder = null;
                    }
                                            
                    if (entryOrder.OrderState == OrderState.Filled
                        && entryOrder.Action == Action.SellShort)
                    
                    {
                        SetProfitTarget("Short", CalculationMode.Ticks, 8);
                        SetStopLoss("Short", CalculationMode.Ticks, 6, false);
                        entryOrder = null;
                    }
                    
                        
                }
            }

    #2
    No where in your code do you have a time filter preventing trades to that time range. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=3226
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      No where in your code do you have a time filter preventing trades to that time range. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=3226

      Would a time filter be needed even when say trading hours are from time XX:XX to YY:YY in the strategy setup?

      Comment


        #4
        If you want to limit trading you should use a time filter.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          I put in the time filter as shown below, and am still having the same issue where the model is sending orders even though its before 8:30... the time filter is the first line

          Code:
                  protected override void OnBarUpdate()
                  {
                      if ((ToTime(Time[0]) >= 83000 && ToTime(Time[0]) < 100000))
                      {
                          // Condition set 1
                          if (High[0] > EMA(Period)[0]
                              && entryOrder == null)
                          {
                              entryOrder = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() + -2 * TickSize, "Long");
                          }
          
                          // Condition set 2
                          if (Low[0] < EMA(Period)[0]
                              && entryOrder == null)
                          {
                              entryOrder = EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 2 * TickSize, "Short");
                          }
                      
                          if (entryOrder != null)
                          {
                              Print(entryOrder.ToString());
                          
                              if (entryOrder.OrderState == OrderState.Working
                                  && entryOrder.Action == Action.Buy
                                  && GetCurrentBid() >= entryOrder.LimitPrice + 4 * TickSize)
                          
                              {
                                  CancelOrder(entryOrder);
                                  entryOrder = null;
                              }
                          
                              if (entryOrder.OrderState == OrderState.Working
                                  && entryOrder.Action == Action.SellShort
                                  && GetCurrentAsk() <= entryOrder.LimitPrice - 4 * TickSize)
                          
                              {
                                  CancelOrder(entryOrder);
                                  entryOrder = null;
                              }
                          
                              if (entryOrder.OrderState == OrderState.Filled
                                  && entryOrder.Action == Action.Buy)
                              {
                                  SetProfitTarget("Long", CalculationMode.Ticks, 8);
                                  SetStopLoss("Long", CalculationMode.Ticks, 6, false);
                                  entryOrder = null;
                              }
                                                  
                              if (entryOrder.OrderState == OrderState.Filled
                                  && entryOrder.Action == Action.SellShort)
                          
                              {
                                  SetProfitTarget("Short", CalculationMode.Ticks, 8);
                                  SetStopLoss("Short", CalculationMode.Ticks, 6, false);
                                  entryOrder = null;
                              }
                          
                          }    
                      }
                  }

          Comment


            #6
            Please add Print()s and figure out where it is entering your code segments.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh that's the thing...
              It's putting out orders at say 85216 even though the replay bar says it is only 81023... i've used these replay files for many strategies without any issue at all (about 100 trading days worth) so I know they are good...

              see the output below...

              PHP Code:
              85216
              Order='NT-00000/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=944.25 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='c46c5bc513734c3ab9a990f58ae10685' Gtd='12/1/2099 12:00:00 AM'
              85502
              Order='NT-00000/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=944.25 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=944.25 Token='c46c5bc513734c3ab9a990f58ae10685' Gtd='12/1/2099 12:00:00 AM'
              85752
              85805
              Order='NT-00003/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=941 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ce43dfd7dabf4e2e8b11cf842c0f3469' Gtd='12/1/2099 12:00:00 AM'
              85925
              Order='NT-00003/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=941 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ce43dfd7dabf4e2e8b11cf842c0f3469' Gtd='12/1/2099 12:00:00 AM'
              85940
              Order='NT-00003/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=941 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=941 Token='ce43dfd7dabf4e2e8b11cf842c0f3469' Gtd='12/1/2099 12:00:00 AM'
              90123
              Order='NT-00006/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=941.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='492a014d6146421a9641125b0ab586ed' Gtd='12/1/2099 12:00:00 AM'
              90307
              Order='NT-00006/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=941.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=941.75 Token='492a014d6146421a9641125b0ab586ed' Gtd='12/1/2099 12:00:00 AM'
              90515
              90604
              90623
              Order='NT-00009/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=939 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='9e7784aecbc546deb6cbfba6a1702f42' Gtd='12/1/2099 12:00:00 AM'
              90724
              Order='NT-00009/Replay101' Name='Short' State=Filled Instrument='ES 06-09' Action=SellShort Limit price=939 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=939 Token='9e7784aecbc546deb6cbfba6a1702f42' Gtd='12/1/2099 12:00:00 AM'
              90808
              Order='NT-00012/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=938.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b997b440a8d04525b32bf0cf9e242532' Gtd='12/1/2099 12:00:00 AM'
              90933
              Order='NT-00012/Replay101' Name='Short' State=Working Instrument='ES 06-09' Action=SellShort Limit price=938.75 Stop price=0 Quantity=1 Strategy='LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b997b440a8d04525b32bf0cf9e242532' Gtd='12/1/2099 12:00:00 AM' 
              

              Comment


                #8
                Not following you. A timestamp of 85216 means 8:52:16 which means you are in the tradeable range.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Josh
                  I've added this screenshot to illustrate what I mean...

                  As you can see... replay is only at 8:10:23... but ninja is placing orders at future time stamps....
                  Attached Files

                  Comment


                    #10
                    The timestamp being printed from the strategy is the timestamp of the replay. It is not processing bars in the future. If you print out every bar's timestamp you will see it has reached there properly.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      but the replay has only reached 8:10am... how could it process timestamps for 9:00 am?

                      Comment


                        #12
                        Please just print the timestamp of every bar and see what time the replay really is at.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Still having the same issues Josh

                          would you happen to have any code snippet with LimitOrders being cancelled if the price deviates after certain number of ticks rather than bars?

                          or is there a way to cancel out limit orders using something other than IOrder?

                          really appreciate your help and patience

                          Comment


                            #14
                            Code:
                            if (Close[0] > entryPrice + 10 * TickSize)
                                 CancelOrder(limitOrder);
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Josh View Post
                              Code:
                              if (Close[0] > entryPrice + 10 * TickSize)
                                   CancelOrder(limitOrder);

                              Just to be sure... where you have CancelOrder(limitOrder) the limitOrder would be the name of the order correct?

                              ie

                              CancelOrder("Long")
                              ?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              670 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X