adarvishian
adarvishian

Reputation: 175

Shifting a plotshape in pinescript

I am building an indicator to detect peaks and have it working fine in thinkscript but need it to work in pine script as well. Thinkscript allows you to offset using future bars but I had to refactor to get a similar output in pine script. Here is what I have so far:

isPeak = (price[1] > (avg[1] + threshold * stdDev[1])) and price < price[1] and price[1] > price[2]
peaks = isPeak ? price[1] : float(na)

This is close, but the problem is that the arrows are one bar ahead of where I want them to paint as seen in the picture. No matter what offset I use in line 2, the arrows do not repaint with a different offset. Any idea on how to get the arrows to paint correctly?

NVDA, 1 Day Timeframe

Upvotes: 0

Views: 860

Answers (1)

vitruvius
vitruvius

Reputation: 21294

plotshape() has an argument called offset which you can use for this purpose.

plotshape(series, title, style, location, color, offset, text, textcolor, editable, size, show_last, display) → void

offset (series int) Shifts shapes to the left or to the right on the given number of bars. Default is 0.

Upvotes: 1

Related Questions