Profit and SL on same tick in backtesting - optimal solution?
I was wondering how backtrader deals with situations where both Profit and SL are hit on the same bar during backtesting. FIFO only works of course if a better timeframe resolution is added; for example if my profit as well as my SL hit on the same 4h-bar during backtesting, the optimal solution would be to look at 2h, or even something like 1-min charts, to see what was hit first.
Is there such an implementation in the backtrader, which I might have missed?
I found a similar question, but not an adequat answer:
Re: What happens when a profit and sto order are filled in the same bar?
Backtrader (similar to real life broker) doesn't make any tricks. It uses FIFO which applicable in any situation. You just need to think about it more.
vladisld last edited by
FIFO only works of course if a better timeframe resolution is added
As @ab_trader said, FIFO works in any case. If multiple orders are filled on the same bar, multiple notifications will be received (notify_order) on this bar - still in FIFO order.
ok, I think I m not making myself clear. Let s say the close price of this 4h bar is 100. Now I go long, with a take profit at 105, and a stop loss at 99. On the next bar, the high is 106 and the low is 98. Which one closed my order, and why?
@jeanpaul order issued first will close your position, next order will open new position. If it will not be cancelled in time.
I found the solution for my question. I didnt realize that I can have multiple timeframes in parallel. This solves my issue of course.