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.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to stop PT and SL from generating double orders in backtest??
Collapse
X
-
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.Tags: None
-
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.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
127 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment