Stop Loss Trigger Issue

 

Hello,

I'm currently developing a system that initiates trades in the last 5-minute candle of every Monday. Ideally, most of these trades should hit the SL at the opening of the next day if there's been a bearish gap, as the SL is set at the lowest point of the current day.

Upon backtesting, I observed exceptionally positive results initially. However, after a closer examination of the chart, I identified an issue:




The SL is being triggered at the initially set price, disregarding trading hours and any gaps. The red circles indicate where the position should be closed, but instead, they are being closed at the level of the SL (yellow line).

There's no much code I can show here, I just place a:

trade.Sell(size, asset, bid, sl, 0, comment)

During backtesting, I used the "Open prices only" modeling. Switching to "Every tick" resolves the issue, but it significantly increases backtest and optimization times, especially with 10 years of data.

One potential workaround is to eliminate the SL and monitor the opening price of each day to adjust positions accordingly. However, this solution feels messy, and I'd prefer to explore other options before commiting to it.

Any insights or suggestions would be greatly appreciated, thanks!