Biztet, I check the code and found the reason why the order is closed with small profit even small loss.
I coded like below as you requested.
1. Buy signal appear.
2. Buy order is placed and sell stop (pending) order is placed at the same time.
3. If Buy order is closed with profit, then delete sell stop order because the signal shows that it is now buy trend.
4. At this moment, if you have another sell order, which was ordered sometime before, this sell order is also closed with sell stop order because it is now buy trend.
This is the reason. Most of time, this sell order is closed with loss trade like your picture.
That is why you have many short time orders with loss.
I changed code to add Minimum profit so that if it is now buy trend, the sell order will be closed only when the sell order profit is more than minimum profit dollar ($5).
This is to avoid small profit loss.
You can set here.
View attachment 94316
View attachment 94317
I tested with Hedge =TRUE
GU M5
View attachment 94318