how bracket function works for stop-loss and take-profit in the same candle?
-
Hello All
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 useself.close
to close any existing orders ( if it was the intended use ). -
-
Please take a look at the following posts for possible clues:
https://community.backtrader.com/topic/3094/bracket-order-with-sl-and-tp-what-happens-when-1-bar-hits-both
https://community.backtrader.com/topic/3046/entry-and-exit-in-the-same-bar-using-bracket-orders