Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to stop PT and SL from generating double orders in backtest??

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

    How to stop PT and SL from generating double orders in backtest??

    Hi,

    I have a strategy that is using bracket orders. When a long signal is triggered, it enters and sets a stop loss/profit target. Same thing for a short signal. The issue is that in backtesting (using IBKR data/Gateway), I see that the signal fires, the trade is taken, and then when the stop loss or profit target executes, the bar immediately after that will execute another trade in the same direction as the last one even though no signal has been triggered. Is this a known bug or something? Has anyone experienced this before? I don't think its my code.

    #2
    Hello UsmanHasan,

    Welcome to the support forums.

    That does not sound like a bug and just that your logic for the entry is still true on the following bar. If the position was closed and the strategy became flat then the EntriesPerDirection would be reset so it could enter again as that is a new bar. If the condition is true then it will enter again.

    In this situation you should use Prints to see how your logic for that condition is equating while it runs in the backtest, that would really be the only way to understand why its working the way it is. You would very likely need to make the condition more specific so that its only true for that single bar or check that it has been at least X number of bars since the last entry.




    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X