0
`//@version=2
strategy("")

threshold = input(title="Price Difference Threshold", type=float, defval=0, step=0.001)

getDiff() =>
yesterday=security(tickerid, 'D', close[1])
today=security(tickerid, 'D', close)
delta=today-yesterday
percentage=delta/yesterday

closeDiff = getDiff()

buying = closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]

hline(0, title="zero line")

bgcolor(buying ? #3399FF : #FFFFFF , transp=1)
plot(closeDiff, color=silver, style=area, transp=75)
plot(closeDiff, color=aqua, title="prediction")

longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)

shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)`

I have pasted Pinescript above it repaint the signal sometimes, so I am asking some help to convert this signal into none repaint. I would really appreciate any help. Thank you all in advance.

1 Answers1

0

You need to wait until the HTF bar is closed if you want to avoid repainting when using secuirty().

You can use the below function:

f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • I don't have knowledge of coding. Can you tell where the function you have asked to use has to be added in the script? Or can you send a completely new one by adding this function to the script? I will be helped by you. Thank you – Dhruv Jain Jul 11 '23 at 09:50