Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

cancelling pending exit order bug

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

    cancelling pending exit order bug

    Is that bug not fixed in NT 7 beta 20? I am still facing the same issue. I open two positons at different prices and fill on stop or target of first entry cancels the stop and target for second entry. Here's the trace log:

    10/08/2010 17:18:00 Entered internal PlaceOrder() method at 10/08/2010 17:18:00: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EnterS1' FromEntrySignal=''
    10/08/2010 17:18:00,15822,47
    10/08/2010 17:18:00 Entered internal PlaceOrder() method at 10/08/2010 17:18:00: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.5822 SignalName='' FromEntrySignal=''
    10/08/2010 17:18:00 Entered internal PlaceOrder() method at 10/08/2010 17:18:00: Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1.5729 StopPrice=0 SignalName='' FromEntrySignal=''
    10/08/2010 19:16:00 Entered internal PlaceOrder() method at 10/08/2010 19:16:00: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EnterS2' FromEntrySignal=''
    SLE2
    10/08/2010 19:16:00 Entered internal PlaceOrder() method at 10/08/2010 19:16:00: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.5821 SignalName='' FromEntrySignal=''
    10/08/2010 19:16:00 Amended open order: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.5821 SignalName=Buy to cover' FromEntrySignal=''
    10/08/2010 19:16:00 Entered internal PlaceOrder() method at 10/08/2010 19:16:00: Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1.5757 StopPrice=0 SignalName='' FromEntrySignal=''
    10/08/2010 19:16:00 Amended open order: Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1.5757 StopPrice=0 SignalName=Buy to cover' FromEntrySignal=''
    10/08/2010 19:18:00 Cancelled pending exit order, since associated position is closed: Order='NT-00002/Backtest' Name='Buy to cover' State=Working Instrument='6B 09-10' Action=BuyToCover Limit price=1.5757 Stop price=0 Quantity=1 Strategy='StdDevMultiTimeFrame' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='895df55e772a40d1bb7dfc2472fce3e9' Gtd='01/12/2099 00:00:00'
    12/08/2010 06:49:00 Entered internal PlaceOrder() method at 12/08/2010 06:49:00: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EnterS2' FromEntrySignal=''
    SLE2
    12/08/2010 06:49:00 Entered internal PlaceOrder() method at 12/08/2010 06:49:00: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.5727 SignalName='' FromEntrySignal=''
    12/08/2010 06:49:00 Entered internal PlaceOrder() method at 12/08/2010 06:49:00: Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1.5659 StopPrice=0 SignalName='' FromEntrySignal=''
    12/08/2010 07:59:00 Cancelled pending exit order, since associated position is closed: Order='NT-00005/Backtest' Name='Buy to cover' State=Working Instrument='6B 09-10' Action=BuyToCover Limit price=0 Stop price=1.5727 Quantity=1 Strategy='StdDevMultiTimeFrame' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4022e94a03c249babf5741c78c620fb8' Gtd='01/12/2099 00:00:00'
    13/08/2010 04:25:00 Entered internal PlaceOrder() method at 13/08/2010 04:25:00: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EnterS2' FromEntrySignal=''
    SLE2
    13/08/2010 04:25:00 Entered internal PlaceOrder() method at 13/08/2010 04:25:00: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.5644 SignalName='' FromEntrySignal=''
    13/08/2010 04:25:00 Entered internal PlaceOrder() method at 13/08/2010 04:25:00: Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1.5579 StopPrice=0 SignalName='' FromEntrySignal=''
    13/08/2010 07:57:00 Cancelled pending exit order, since associated position is closed: Order='NT-00009/Backtest' Name='Buy to cover' State=Working Instrument='6B 09-10' Action=BuyToCover Limit price=1.5579 Stop price=0 Quantity=1 Strategy='StdDevMultiTimeFrame' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b4ab98e937ba472e90a925cafbd1905c' Gtd='01/12/2099 00:00:00'
    16/08/2010 06:54:00 Entered internal PlaceOrder() method at 16/08/2010 06:54:00: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EnterS2' FromEntrySignal=''
    SLE2
    16/08/2010 06:54:00 Entered internal PlaceOrder() method at 16/08/2010 06:54:00: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.5626 SignalName='' FromEntrySignal=''
    16/08/2010 06:54:00 Entered internal PlaceOrder() method at 16/08/2010 06:54:00: Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1.5566 StopPrice=0 SignalName='' FromEntrySignal=''
    16/08/2010 07:31:00 Cancelled pending exit order, since associated position is closed: Order='NT-00012/Backtest' Name='Buy to cover' State=Working Instrument='6B 09-10' Action=BuyToCover Limit price=1.5566 Stop price=0 Quantity=1 Strategy='StdDevMultiTimeFrame' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='e010fabe721343f680dcd31747018097' Gtd='01/12/2099 00:00:00'

    #2
    morphtrade, can you please post the code you're using so we can test it out here?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Code:
       protected override void OnBarUpdate()
              {
                  if (BarsInProgress != 1) return;
                             
              (SomeCustomIndicatorCondition....)    
                  {
                      if (Position.MarketPosition != MarketPosition.Flat) return;
                      int barsSinceEntry = BarsSinceEntry(seriesIndex, "EnterS", 0);              
                      if (barsSinceEntry < iEntryDiff && barsSinceEntry != 0) return;
                      if (barsSinceEntry == 0 && Performance.ShortTrades.Count > 0) return;
                      orderEntry1 = EnterShort(1, 1, "EnterS1");
                     
                  }
              (SomeCustomIndicatorCondition....)    
                  {
                      if (Position.MarketPosition != MarketPosition.Short || orderEntry2 != null) return;
                      orderEntry2 = EnterShort(1, 1, "EnterS2");
                  }
              }
              protected override void OnOrderUpdate(IOrder order)
              {
                  if (order.OrderState == OrderState.Filled)
                  {
                      if (orderEntry1 != null && orderEntry1.OrderId == order.OrderId)
                      {
                          if (order.OrderAction == OrderAction.SellShort)
                          {
                              ExitShortStop(1, true, 1, DoublePrice(priceSLShort), "", "");
                              ExitShortLimit(1, true, 1, DoublePrice(priceEntryShort1 - PT1), "", "");
                              orderEntry1 = null;
                          }
                      }
                      if (orderEntry2 != null && orderEntry2.OrderId == order.OrderId)
                      {
                          if (order.OrderAction == OrderAction.SellShort)
                          {
                              ExitShortStop(1, true, 1, DoublePrice(priceSLShort), "", "");
                              ExitShortLimit(1, true, 1, DoublePrice(priceEntryShort2 - PT1), "", "");
                              orderEntry2 = null;
                          }
                      }
                      
                  }
                  
              }

      Comment


        #4
        morphtrade, please specify unique signal names for each entry and exit method you call and let me know if that does the trick. Currently, the signal names are all blank (""), which would indeed link exits together.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Which signal names are you mentioning? Because I have used "EnterS1" and "EnterS2" as signal names.

          Comment


            #6
            morphtrade, I am referring to the exit signal names, which specify the blank entry name. Also, please ensure you are using 'PerEntryExecution' for the stop and target handling when running this strategy.
            Attached Files
            AustinNinjaTrader Customer Service

            Comment


              #7
              it still cancels the order:

              04/01/2010 14:05:00 Entered internal PlaceOrder() method at 04/01/2010 14:05:00: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EntryL1' FromEntrySignal=''
              04/01/2010 14:05:00 Entered internal PlaceOrder() method at 04/01/2010 14:05:00: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EntryL2' FromEntrySignal=''
              04/01/2010 14:05:00 Entered internal PlaceOrder() method at 04/01/2010 14:05:00: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4385 SignalName='StopLoss' FromEntrySignal=''
              04/01/2010 14:05:00 Entered internal PlaceOrder() method at 04/01/2010 14:05:00: Action=Sell OrderType=Limit Quantity=1 LimitPrice=1.4457 StopPrice=0 SignalName='ProfitTraget1' FromEntrySignal='EntryL1'
              04/01/2010 14:05:00 Entered internal PlaceOrder() method at 04/01/2010 14:05:00: Action=Sell OrderType=Limit Quantity=1 LimitPrice=1.4457 StopPrice=0 SignalName='ProfitTraget2' FromEntrySignal='EntryL2'
              04/01/2010 14:05:00 Ignored PlaceOrder() method at 04/01/2010 14:05:00: Action=Sell OrderType=Limit Quantity=1 LimitPrice=1.4457 StopPrice=0 SignalName='ProfitTraget2' FromEntrySignal='EntryL2' Reason='SignalName does not have a matching FromEntrySignal to exit'
              05/01/2010 05:49:00 Cancelled pending exit order, since associated position is closed: Order='NT-00002/Backtest' Name='StopLoss' State=Working Instrument='6E ##-##' Action=Sell Limit price=0 Stop price=1.4385 Quantity=1 Strategy='BDB' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='63e993ecf4bb4615b87241c98ce63713' Gtd='01/12/2099 00:00:00'
              Code:
              protected override void OnBarUpdate()
                      {            
                          if (BarsInProgress == 1)
                          {
                              if (Position.MarketPosition != MarketPosition.Flat) return;
                              if (dHigh != 0 && High[0] > dHigh)
                              {
                                  orderEntry1 = EnterLong(1, 1, "EntryL1");
                                  if (PT2 != 0) orderEntry2 = EnterLong(1, 1, "EntryL2");
                                  priceStop = dLow;
                                  dHigh = 0;
                                  dLow = 0;
                                  return;
                              }
                              if (dLow != 0 && Low[0] < dLow)
                              {
                                  orderEntry1 = EnterShort(1, 1, "EntryS1");
                                  if (PT2 != 0) orderEntry2 = EnterShort(1, 1, "EntryS2");
                                  priceStop = dHigh;
                                  dLow = 0;
                                  dHigh = 0;
                              }
                          }
                      }
                      protected override void OnOrderUpdate(IOrder order)
                      {
                          if (order.OrderState != OrderState.Filled) return;
                          if (orderEntry1 != null && orderEntry1 == order)
                          {
                              if (order.OrderAction == OrderAction.SellShort)
                              {
                                  double priceLimit = order.AvgFillPrice - (PT1 * TickSize);
                                  ExitShortStop(1, true, 1, priceStop, "StopLoss", "");
                                  ExitShortLimit(1, true, 1, priceLimit, "ProfitTraget1", "EntryS1");
                                  if (orderEntry2 != null) ExitShortLimit(1, true, 1, priceLimit, "ProfitTraget2", "EntryS2");
                                  orderEntry1 = null;
                                  orderEntry2 = null;
                              }
                              if (order.OrderAction == OrderAction.Buy)
                              {
                                  double priceLimit = order.AvgFillPrice + (PT1 * TickSize);
                                  ExitLongStop(1, true, 1, priceStop, "StopLoss", "");
                                  ExitLongLimit(1, true, 1, priceLimit, "ProfitTraget1", "EntryL1");
                                  if (orderEntry2 != null) ExitLongLimit(1, true, 1, priceLimit, "ProfitTraget2", "EntryL2");
                                  orderEntry1 = null;
                                  orderEntry2 = null;
                              }
                          }
                      }
              Last edited by morphtrade; 08-19-2010, 06:40 AM.

              Comment


                #8
                It works if I use SetProfitTarget("EntryL1", CalculationMode.Ticks, PT1); but why not with ExitShortStop.

                Comment


                  #9
                  Hello morphtrade,

                  If you are interested in scaling out of a postition, you must work closely according to this reference sample:
                  http://www.ninjatrader.com/support/f...ead.php?t=3751

                  I attached a simple strategy here that shows scaling and and out working as expected. The 2nd level stop is not canceled when the first is hit.

                  Start simple and then add complexity only after you've verified behavior at each step. Let us know if you are still seeing unexpected results.
                  Attached Files
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    It is fine. I moved to unmanaged approach. It's much better as I have more control over cancelling and updating orders.

                    Comment


                      #11
                      Thanks for the update here, morphtrade.
                      Ryan M.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by smk200, Today, 10:29 AM
                      1 response
                      14 views
                      0 likes
                      Last Post NinjaTrader_ChrisL  
                      Started by Austiner87, Today, 09:44 AM
                      2 responses
                      23 views
                      0 likes
                      Last Post Austiner87  
                      Started by TriGuy818, Today, 09:19 AM
                      2 responses
                      14 views
                      0 likes
                      Last Post TriGuy818  
                      Started by 7robert, Today, 09:12 AM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Kate  
                      Started by space_trader, Today, 09:11 AM
                      2 responses
                      29 views
                      0 likes
                      Last Post space_trader  
                      Working...
                      X