Page 1 of 1

Sell an buy at same candle

Posted: Wed Apr 05, 2023 7:08 am
by Firebird1234
Hi all,
during my backtesting I discovered, that a couple of orderPositions (Sell and Buy) were made at the same candle in the chart (same time).
As this is not tradable in realtime I want to avoid this situation.

Is it possible to configure strategy.exit in a way, that the exit strategy is started one candle later?

Thanks for your answers.

Re: Sell an buy at same candle

Posted: Thu Apr 06, 2023 10:42 am
by Steve Burman
I'm not sure whether there's an option in the strategy.exit, however, you can check for strategy.position_size == 0 on your buy and sell signal which will prevent this happening such as:

if buySignal and strategy.position_size == 0
strategy.entry(id='Long', direction=strategy.long)
if sellSignal and strategy.position_size == 0
strategy.entry(id='Short', direction=strategy.short)

OR

if strategy.position_size == 0
if buySignal
strategy.entry(id='Long', direction=strategy.long)
if sellSignal
strategy.entry(id='Short', direction=strategy.short)