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.
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        Comment


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

          Regards,
          Kylie.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by elirion, Today, 01:36 AM
          0 responses
          3 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Started by samish18, Yesterday, 08:31 AM
          2 responses
          9 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by Mestor, 03-10-2023, 01:50 AM
          16 responses
          391 views
          0 likes
          Last Post z.franck  
          Started by rtwave, 04-12-2024, 09:30 AM
          4 responses
          34 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Working...
          X