how bracket function works for stop-loss and take-profit in the same candle?
Behnam Heydari last edited by
I've used the following code to buy or sell after the signal created in the "next" function.
if position_type == 'buy': brackets = self.buy_bracket(limitprice=position.take_profit, price=position.start, stopprice=position.stop_loss) elif position_type == 'sell': brackets = self.sell_bracket(limitprice=position.take_profit, price=position.start, stopprice=position.stop_loss)
the problem is when take-profit and stop-loss occurred in the same candle, observation shows for example if the signal is buying, Backtrader will buy in this candle and sell in the opening of next candle, that this it not suitable for me.
the best scenario in this situation is to check the lower time-frame to find out which is occurred first, is this possible to customize it someway to achieve this requirement?
Thanks in advance.
I exactly don't understand your question. But if you want the signal and trade to be on same candle you can use
cheat-on-close. Also use
self.closeto close any existing orders ( if it was the intended use ).
run-out last edited by
vladisld last edited by
Please take a look at the following posts for possible clues: