Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

3rd stop order is never sent to execution

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

    3rd stop order is never sent to execution

    Two questions:
    1. Is there an easy way to simply cancel all unfilled entry orders when stops are hit. My program scales in and out of positions, when one of those positions is stopped, i want all unfilled entries to cancel. Currently I'm doing the following but it does not seem to work unless I call it within the OnBarUpdate method.

      Code:
                                 if(entryOrder1 != null)
                                  {                            
                                      CancelOrder(entryOrder1);
                                  }
                                  if(entryOrder2 != null)
                                  {                            
                                      CancelOrder(entryOrder2);
                                  }
                                  if(entryOrder3 != null)
                                  {
                                      CancelOrder(entryOrder3);
                                  }
      Is it not possible to call this within the OnExecution method? No errors are given when I do, but it does not have the same result as when I call it from OnBarUpdate
    2. I have 3 stops (one for each of my 3 entries). When they are stopped I want the function in question 1 to occur. However I'm noticing that when the strategy hits its stops, only stop1 and stop2 make calls to the OnExecution method. Even though I see stop3 WAS hit on the chart, the code never reaches it within the OnExecution method. Do you have any idea as to why? I've checked my code 100 times over and there is no difference between the way stop1 2 and 3 are handled.

    #2
    1. You can call CancelOrder() anywhere in the code, whether that is OnExecution() or OnBarUpdate().

    2. What I recommend is turning TraceOrders = true and seeing what exactly is happening with your 3rd stop. Following OnOrderUpdate() may be just as valuable as following OnExecution() is to understand what the order is doing. I also suggest printing from those methods with no filter attached to ensure you are not filtering for the order incorrectly.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      thank you, I was unaware of the TraceOrders function.

      However after using it I have discovered that it doesn't seem as though the issue is with my code, but in how NT handles the last stop order.

      Within OnExecution() I have the following to perform an action.

      Code:
      if (stopOrderX != null && stopOrderX == execution.Order)
      {
        Print("Code has been reached");
        //DO SOMETHING
      }
      Where x is some number designating the stop. For some reason the last stop is never hit because the final stop never gets sent to OnExecution (even though it displays as stopped on the chart). At first it was stopOrder3. Then I removed the 3rd entry and tried it with just two (these two worked flawlessly when the third is in play). However when I remove the third the 2nd one begins not being hit. My trace Output looks as follows when the stops are hit.


      10/18/2010 2:19:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00003/Sim101' Name='Limit Short Exit 1' State=Working Instrument='ES 12-10' Action=BuyToCover Limit price=1165.89795918367 Stop price=0 Quantity=1 Strategy='PBTrade' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='08ddbcb11bf4421a8f053f4399328156' Gtd='12/1/2099 12:00:00 AM'
      Code has been reached (this is the correct output)
      10/18/2010 2:19:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00005/Sim101' Name='Limit Short Exit 2' State=Working Instrument='ES 12-10' Action=BuyToCover Limit price=1164.87448979592 Stop price=0 Quantity=1 Strategy='PBTrade' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='3b7dcdaa158d459a9f77e2a8fae2b850' Gtd='12/1/2099 12:00:00 AM'
      HERE NOTHING PRINTS - BECAUSE stopOrder2 == execution.Order IS NEVER TRUE

      When there are three positions in play the same thing happens (only with the last stop)

      10/18/2010 2:19:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00004/Sim101' Name='Limit Short Exit 1' State=Working Instrument='ES 12-10' Action=BuyToCover Limit price=1165.89795918367 Stop price=0 Quantity=1 Strategy='PBTrade' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a0edc94527564649abf94ba17d7eab02' Gtd='12/1/2099 12:00:00 AM'
      Code has been reached (this is the correct output)
      10/18/2010 2:19:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00006/Sim101' Name='Limit Short Exit 2' State=Working Instrument='ES 12-10' Action=BuyToCover Limit price=1164.87448979592 Stop price=0 Quantity=1 Strategy='PBTrade' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='3b043e8ea4244cfdbaffd6deece38a88' Gtd='12/1/2099 12:00:00 AM'
      Code has been reached (this is the correct output)
      10/18/2010 2:19:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00008/Sim101' Name='Limit Short Exit 3' State=Working Instrument='ES 12-10' Action=BuyToCover Limit price=1141.5 Stop price=0 Quantity=1 Strategy='PBTrade' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='c8988a4defa84ef7b5063df08156f2d9' Gtd='12/1/2099 12:00:00 AM'
      HERE NOTHING PRINTS - BECAUSE stopOrder3 == execution.Order IS NEVER TRUE

      Comment


        #4
        You will want to trace your actually IOrder object of stopOrder3.

        I suggest you print without filtering from OnOrderUpdate() and OnExecution(). Just do:

        Code:
        Print(order.ToString());
        Print(execution.ToString());
        respectively in the methods.

        You will want to check your code for proper creation of stopOrder3 as well and proper assignment of it.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          thank you for that tidbit of printing info. It allowed me to see that when the last stop was being executed Position.MarketPosition == MarketPosition.Short was no longer true because it was already flat... thus the last stop would never properly execute the follow up code.

          thanks again for all your help. I can finally get back to working on the actual trade logic now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          646 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          367 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X