'repainting problem in security() function

I have some problem with security() function in pinescript

When I use the following code the repainting problem is solved but the winrate is negetive

f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[45], lookahead = barmerge.lookahead_on)

o = f_secureSecurity(syminfo.tickerid, res5, open)
c = f_secureSecurity(syminfo.tickerid, res5, close)
hz = f_secureSecurity(syminfo.tickerid, res5, high)
l = f_secureSecurity(syminfo.tickerid, res5, low)

I find other way to fix security() reoainting problem from this link When i use the following code the winrate is positive but in playback again we have repainting problem

f_secureSecurity(_symbol, _res, _src, _repaint) => security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0], lookahead = barmerge.lookahead_on )[_repaint ? 0 : barstate.ishistory ? 0 : 1]

o = f_secureSecurity(syminfo.tickerid, res5, open,false)
c = f_secureSecurity(syminfo.tickerid, res5, close)
hz = f_secureSecurity(syminfo.tickerid, res5, high)
l = f_secureSecurity(syminfo.tickerid, res5, low)

is there anyway to fix this problem ? i need help :)



Sources

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

Source: Stack Overflow

Solution Source