'Problem of Pinescript converting from V2 to V5

I converted this tradingview pinescript from v2 to v5, and I found that the buy sell signals was different when comes to the candlestick chart. Anyone know what is the problem?'

//@version=2
strategy(title='Testing Strategy', shorttitle='Testing_Strategy', overlay=true,pyramiding=0, initial_capital=1000, currency=currency.USD)
period = input('720')
ch1 = security(tickerid, period, open)
ch2 = security(tickerid, period, close)
longCondition = crossover(security(tickerid, period, close),security(tickerid, period, open))
if (longCondition)
strategy.entry("BUY", strategy.long)
shortCondition = crossunder(security(tickerid, period, close),security(tickerid, period, open))
if (shortCondition)
strategy.entry("SELL", strategy.short)

//@version=5
strategy(title='Testing Strategy', shorttitle='Testing_Strategy', overlay=true, 
pyramiding=0, initial_capital=1000, currency=currency.USD)
period = input('720')
ch1 = request.security(syminfo.tickerid, period, open)
ch2 = request.security(syminfo.tickerid, period, close)
longCondition = ta.crossover(request.security(syminfo.tickerid, period, close), request.security(syminfo.tickerid, period, open))
if longCondition
strategy.entry('BUY', strategy.long)
shortCondition = ta.crossunder(request.security(syminfo.tickerid, period, close), request.security(syminfo.tickerid, period, open))
if shortCondition
strategy.entry('SELL', strategy.short)


Solution 1:[1]

Default behaviour of lookahead argument of the security function has changed starting from version 3. Reference.

Default value is barmerge.lookahead_off starting from version 3. So, your v2 script had it as barmerge.lookahead_on. Add lookahead=lookahead_on to your security calls and it should be good.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vitruvius