Hi
I have been using Backtrader for a couple of weeks now and I would like to thank the developers and community for this amazing tool.
While looking at the output of a 2 SMA crossover with bracket orders, i notice that if i use the close price for a day as the price for buy/sell, the order is executed the next day as expected and if possible.
However, a stop loss takes 2 days to trigger even though the range of values on the day of the purchase should trigger it.
Consider:
Date,Open,High,Low,Close,Adj Close,Volume
2004-10-04,1.240202,1.243503,1.226001,1.241095,1.241095,0
2004-10-11,1.241203,1.250000,1.223496,1.248206,1.248206,0
2004-10-18,1.248299,1.272993,1.245501,1.272896,1.272896,0
And consider the output:
CrossUp On:2004-10-04 23:59:59.999989 Buy Price:1.241095 Stop Price:1.239095 Take Profit:1.243095 (inside next)
2004-10-11: Order ref: 1 / Type Buy / Status Completed Created At 1.241095 Executed At 1.241095 Current Position 62054 (inside notify_oder)
2004-10-18: Order ref: 3 / Type Sell / Status Completed Created At 1.243095 Executed At 1.248299 Current Position 0 (inside notify_order)
My stop loss had the value 1.243095 and the range of values for 2004-10-11 was [1.223496,1.250000] which should trigger it.
At the same time, I understand that this is a complicated problem to solve and this may have been a decision. I notice that for orders, the opening price is used first for comparison and if the price does not trigger the order (e.g. opening price is not higher than my stop loss for a long position), then the daily range is used.
With the stop loss case, it is hard to trigger on the same day as the purchase because in real life, with the limited data that is provided (e.g. weekly data) , you can't really tell if the price that triggers the buy comes before the stop or vice-versa, so you push the order to the next day where it is easier to make a valid assumption.
I hope this makes sense. I checked the code and even though i have coded for many years, sometimes getting used to other people's code take me some time.
Thanks in advance.