Search code examples
pine-scriptpine-script-v5pine-script-v4

Is it possible to make this non repainting one with having same results on live chart?


/@version=5
indicator(title='Simple Buy/Sell', overlay=true)

//Signals
buy = (high > open[1]) and not (low < open[1])
sell = (low < open[1]) and not (high > open[1])

//Plots
plotshape(buy, style=shape.labelup, location=location.belowbar, size=size.tiny)
plotshape(sell, style=shape.labeldown, location=location.abovebar, size=size.tiny)

Is there a way to make non repaint signals on live charts without using

buy = (high[1] > open[2]) and not (low[1] < open[2])
sell = (low[1] < open[2]) and not (high[1] > open[2])

I tried many things but nothing works like the above script.


Solution

  • You can use the barstate.isconfirmed built-in variable. That will wait until the bar is closed and then evaluate your condition.

    Returns true if the script is calculating the last (closing) update of the current bar. The next script calculation will be on the new bar data.