Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Stoploss order being canceled spontaneously in historical backtest

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

    Stoploss order being canceled spontaneously in historical backtest

    I think I am having the same issue as this poster on the beta version:


    Was that issue ever resolved? My stop loss orders are being spontaneously canceled. I too am using multi-series strategy. My stop orders get "accepted" and "working", but then spontaneously canceled a few bars later (anywhere from 5-50 minutes later).

    Using a Print statement for debug purposes, I get this output during one round-trip of buy-sell:

    Code:
    OnOrderUpdate(...){
         Print(order.Name +"   " + order.OrderState + "     " + Time[0]);	
    }
    OUTPUT:
    Buy Submitted 8/16/2012 9:34:00 AM
    Buy Accepted 8/16/2012 9:34:00 AM
    Buy Working 8/16/2012 9:34:00 AM
    Stop loss Submitted 8/16/2012 9:34:00 AM
    Stop loss Accepted 8/16/2012 9:34:00 AM
    Stop loss Working 8/16/2012 9:34:00 AM
    Buy Filled 8/16/2012 9:34:00 AM
    Stop loss CancelPending 8/16/2012 9:42:00 AM
    Stop loss CancelSubmitted 8/16/2012 9:42:00 AM
    Stop loss Cancelled 8/16/2012 9:42:00 AM
    Sell Submitted 8/16/2012 3:11:00 PM
    Sell Accepted 8/16/2012 3:11:00 PM
    Sell Working 8/16/2012 3:11:00 PM
    Sell Filled 8/16/2012 3:11:00 PM

    The example above happened to be a profitable trade, and my stop loss was never hit. But what scares me is the fact that it was canceled spontaneously during a bar in which no other orders were placed.

    #2
    Hello YD777,

    Thanks for your post.

    Yes, 10342 was resolved in the Beta release 8.0.0.14 (RC2) dated October 6, 2016. Here is a link to the release notes (available in the helpguide) http://ninjatrader.com/support/helpG.../?8_0_0_14.htm

    As I do not know how you have coded your strategy, in looking at the SetStopLoss() method what may relate is the note: Should you have multiple Bars objects of the same instrument while using SetStopLoss() in your strategy, you should only submit orders for this instrument to the first Bars context of that instrument. This is to ensure your order logic is processed correctly and any necessary order amendments are done properly. Reference http://ninjatrader.com/support/helpG...etstoploss.htm

    If that does not relate, please post your code or a working sample of the code that will demonstrate the issue. along with the steps to recreate. If you prefer not to post please feel free to send into PlatformSupport[at]NinjaTrader[dot]Com. Mark the e-mail subject Atten:Paul and a link to this thread.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul for offering your help. I have been trying to debug with no luck. It happens on even the most basic of code (see example below), so I feel it must be a bug. The only thing required to recreate the problem is having secondary bars. For instance, take this useless strategy below as an example. I don't even use the secondary bars I added.

      Code:
      protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Name = "strategyTEST";
                      Calculate = Calculate.OnBarClose;
                      EntriesPerDirection = 1;
                      EntryHandling = EntryHandling.AllEntries;
                      IsExitOnSessionCloseStrategy = true; 
                      ExitOnSessionCloseSeconds = 30;
                      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                      StartBehavior = StartBehavior.WaitUntilFlat;
                      TimeInForce = TimeInForce.Gtc;
                      TraceOrders = false;
                      StopTargetHandling = StopTargetHandling.PerEntryExecution;
                      BarsRequiredToTrade = 1;
                  }
                  else if (State == State.Configure)
                  {
      		AddDataSeries("IBM", BarsPeriodType.Minute, 1);
                      SetStopLoss(CalculationMode.Currency, 150); 
                  }
      
              }
      				
              protected override void OnBarUpdate()
              {
                  if ((BarsInProgress != 0))
                      return;
      																		
      	    EnterLong(1);				
              }
      Few notes about my problem:
      1. My primary bars are ES ##-## (1 minute) in the example above
      2. Secondary bars can be any other instrument. Can be a stock or future.
      3. If you back test the above code over years, you'll see that most of the time the stop loss works, but a few "random" times the stop order is spontaneously canceled for no apparent reason
      4. The specific trades when the stop loss gets canceled depends on what instrument is added for secondary bars! Even though in the example above the secondary bars have no significance to the strategy! Compare the differences using IBM vs YM ##-## as secondary bars.
      5. Using OnOrderUpdate( ) to follow each trade, you can see that the specific time the stop loss gets canceled also changes based on what secondary bars are being used
      Last edited by YD777; 04-21-2017, 10:58 PM.

      Comment


        #4
        Hello YD777,

        Thanks for your reply.

        I've used your basic example (Thanks!) but have not been able to recreate the condition.

        What version of NinjaTrader8 are you using (Help>about)?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Version: 8.0.5.2 64-bit

          Again, the problem does not happen often, so you may have to back test over a long period of time and with different instruments as the secondary bars to see it happen. If you take the code below, and back test with the two data files I've attached from 1/1/2014 to 1/5/2014, you will get one bad trade on 1/2/2014. I also attached the chart... the stop loss should have been triggered at 1828.25, but instead it is canceled and the price dips all the way to 1825.75 before climbing back up and closing at 1827.25 (exit on session close).


          Code:
              public class strategyTEST : Strategy
              {
          
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Name = "strategyTEST";
                          Calculate = Calculate.OnBarClose;
                          EntriesPerDirection = 1;
                          EntryHandling = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy = true; 
                          ExitOnSessionCloseSeconds = 30;
                          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                          StartBehavior = StartBehavior.WaitUntilFlat;
                          TimeInForce = TimeInForce.Gtc;
                          TraceOrders = false;
                          StopTargetHandling = StopTargetHandling.PerEntryExecution;
                          BarsRequiredToTrade = 1;
                      }
                      else if (State == State.Configure)
                      {
          				AddDataSeries("XYZ", BarsPeriodType.Minute, 1);
                          SetStopLoss(CalculationMode.Currency, 100); 
                      }
          
                  }
          				
                  protected override void OnBarUpdate()
                  {
                      if ((BarsInProgress != 0))
                          return;
          																		
          			EnterLong(1);				
                  }
          The XYZ data file should be added as a stock.
          Attached Files

          Comment


            #6
            Hello YD777,

            Thanks for your reply.

            Please update to the latest version of NT8 (8.0.6.0) so that we are testing with the same version. Between versions that are a number of changes that have been made. While I don't know of anything specific that addresses what you are seeing the first step really is being on the current version and testing for the issue.

            Here is a link to the download site: http://ninjatrader.com/PlatformDirect

            Thank-you.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              I upgraded to 8.0.6.0 and problem is same. Stop order still canceled as before.

              Comment


                #8
                Hello YD777,

                Thanks for updating.

                Please send an e-mail to PlatformSupport[at]NinjaTrader[dot]Com with your log and trace files attached for review. In the subject line please put: Atten:Paul and a link to this thread.

                Please follow the steps below to manually attach your log and trace files to your e-mail
                • Open your NinjaTrader folder under Documents.
                • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
                • Send the 2 compressed folders as attachments to this email.
                • Once complete, you can delete these compressed folders.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  I can do that when I'm back to my home computer. But were you not able to recreate the problem with the data files I already sent you?

                  Comment


                    #10
                    Any updates?

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Christopher_R, Today, 12:29 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post Christopher_R  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    166 responses
                    2,235 views
                    0 likes
                    Last Post sidlercom80  
                    Started by thread, Yesterday, 11:58 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post thread
                    by thread
                     
                    Started by jclose, Yesterday, 09:37 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post jclose
                    by jclose
                     
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    10 responses
                    1,415 views
                    0 likes
                    Last Post Traderontheroad  
                    Working...
                    X