Firebird1234
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: April 5th, 2023

Sell an buy at same candle

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.

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Sell an buy at same candle

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)

Return to “Pine Script Q&A”