Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wrong stop loss order being triggered in backtest

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

    Wrong stop loss order being triggered in backtest

    Hi,

    I am backtesting my strategy and it is generally working as planned with the exception of the following scenario:

    I have an initial stop loss (using ExitLongStop with signal name "Initial SL") and then as the position moves in my favour, I change to a trailing stop loss (using ExitLongStop with signal name "ATR Stop"). In most circumstances, this works fine and just cancels the pending "Initial SL" exit order if the trailing stop order is filled. However in one scenario during the backtest, the market goes through both stop orders in one bar but the system picks the lower Initial SL order to process, not the higher trailing stop loss order.

    I assume in live trading this should work correctly with the higher stop being triggered first, but I wanted to get an understanding why this would happen during backtesting?

    I guess I could cancel the initial stop loss order when the trailing stop loss order is submitted, but I didn't mind the idea of having both there as a failsafe if something went wrong with one of the orders.

    Any thoughts would be much appreciated.

    Regards,
    Kylie.

    #2
    kylie, you would need to run with TraceOrders = true in order to debug the order behavior 'under the hood' you would get - best would be just using the same signal name and just update / amend the stop value then.

    Comment


      #3
      Hi Bertrand,

      I have been running TraceOrders and can see where it posts the initial entry order, initial stop loss order, initial trailing stop order and then amends the trailing stop order as it goes higher. However, in the bar that passes through both orders, it hits the lower initial stop order and cancels the higher trailing stop order (10/11 5.30pm)

      Code:
       
      10/11/2010 5:15:00 PM Entered internal PlaceOrder() method at 10/11/2010 5:15:00 PM: Action=Buy OrderType=Market Quantity=62,500 LimitPrice=0 StopPrice=0 SignalName='LongEntry' FromEntrySignal=''
      10/11/2010 5:15:00 PM Entered internal PlaceOrder() method at 10/11/2010 5:15:00 PM: Action=Sell OrderType=Stop Quantity=62,500 LimitPrice=0 StopPrice=1.3771'5 SignalName='Initial SL' FromEntrySignal='LongEntry'
      10/11/2010 5:20:00 PM Entered internal PlaceOrder() method at 10/11/2010 5:20:00 PM: Action=Sell OrderType=Stop Quantity=62,500 LimitPrice=0 StopPrice=1.3778 SignalName='ATR Stop' FromEntrySignal='LongEntry'
      10/11/2010 5:25:00 PM Entered internal PlaceOrder() method at 10/11/2010 5:25:00 PM: Action=Sell OrderType=Stop Quantity=62,500 LimitPrice=0 StopPrice=1.3781'5 SignalName='ATR Stop' FromEntrySignal='LongEntry'
      10/11/2010 5:25:00 PM Amended open order: Action=Sell OrderType=Stop Quantity=62500 LimitPrice=0 StopPrice=1.3781'5 SignalName=ATR Stop' FromEntrySignal='LongEntry'
      10/11/2010 5:30:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00066/Back101' Name='ATR Stop' State=Working Instrument='$EURUSD' Action=Sell Limit price=0 Stop price=1.37815 Quantity=62,500 Strategy='Cust123BotLong' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ae04b13297384e6d961b11bcfa7120db' Gtd='1/12/2099 12:00:00 AM'
      I thought you used the Signal Name field to specify when different things are triggering your order, but if I need to put it all under the same name to get around this situation it is not a big deal. If there is a logical explanation though, it would be great to know.

      Regards,
      Kylie.

      Comment


        #4
        kylie, that might be the case - you could not control which order gets filled first if it completely trades through to actually trigger both pricewise - if you just amend by using the same signal name you work with one order in total which would be the easiest to manage.

        Comment


          #5
          Thanks Bertrand. I will change them to be the same.

          Regards,
          Kylie.

          Comment

          Latest Posts

          Collapse

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