Pine script version change and stop reprint and repaint issue

62 Views Asked by At

Here is a very small pine script that follows trend but I'm facing issue with this repaint and reprint issue.

//@version=2

strategy("PrabhuTrendStrategy", overlay=true)

tim=input('160')

out1 = security(tickerid, tim, open)
out2 = security(tickerid, tim, close)

plot(out1,color=red)
plot(out2,color=green)

longCondition = crossover(security(tickerid, tim, close),security(tickerid, tim, open))

if (longCondition)
    strategy.entry("long", strategy.long)

shortCondition = crossunder(security(tickerid, tim, close),security(tickerid, tim, open))

if (shortCondition)
    strategy.entry("short", strategy.short)
1

There are 1 best solutions below

0
vitruvius On

In //@version=2, the lookahead argument is set to barmerge.lookahead_on which will cause repainting.

Upgrade your code to v5 and use the below function for non-repainting security function shared here.

// Function to securely and simply call `security()` so that it never repaints and never looks ahead.
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)