Issue with alerts on indicators that use offsets
If an alert is created on an indicator that uses plots with offsets, then when comparing the alert signal with the signal on the chart, it may seem that the alert is triggered with a delay.
Let's look at an example: an alert triggered when pivotHigh is detected.
pivotHigh is a high whose value is greater than a certain number of previous and subsequent high values. (There are more than two previous and subsequent high values in this example.)
You can find a bar where the above condition is met using this Pine script:
//@version=6
indicator("PivotHigh", overlay=false)
plot(high)
plot(high, linewidth=2, style = plot.style_circles)
phDetected =
high[2] > high[0]
and high[2] > high[1]
and high[2] > high[3]
and high[2] > high[4]
plotshape(phDetected?high[2]:na, style=shape.labeldown, location=location.absolute, text="pivotHigh", textcolor=color.white, color=color.green, offset=0)
alertcondition(phDetected)
When adding the script to the chart, we see the label displayed on the bar from 16:30, although pivotHigh is located 2 bars to the left.
If you create an alert on alertcondition from a script, it will also trigger on the bar from 16:30 since the pivotHigh detection condition is met on it.
We can add an offset to the plotshape function to display the label on the pivotHigh bar.
plotshape(phDetected?high[2]:na, style=shape.labeldown, location=location.absolute, text="pivotHigh", textcolor=color.white, color=color.green, offset=-2)
Such an offset is needed only for convenience (it is often used in divergence indicators) and does not affect the alert triggering, i.e., the alert will still trigger correctly on the bar from 16:30. However, it may seem that it should trigger earlier (namely, on the bar from 14:30).