How to sell at end of candle but buy at open on another in Trading View?

23 views Asked by At

How can I let a Trading View strategy in Pinescript v5 go long at the open of the next day after entry conditions are met, but sell at the close(!) of just the day the exit conditions are met?

It is no solution to use process_orders_on_close=true, because it prevents TV from buying at the open of the next candle.

The code snippet so far is this:

longCondition = up_cross
exitCondition = down_cross

// Buy at Open of Next Candle
strategy.entry("Long", strategy.long, when=longCondition and time >= startDate and time <= endDate ? open : na)

// Sell at Close of Day
strategy.close("Long", when=exitCondition and time >= startDate and time <= endDate ? close : na)
0

There are 0 answers