오프셋을 쓰는 인디케이터의 얼러트 문제
오프셋이 있는 플롯을 쓰는 인디케이터에 얼러트를 만들면 얼러트 시그널을 차트 위 시그널과 비교할 때 지연이 있는 상태에서 얼러트가 트리거되는 것처럼 보일 수 있습니다.
예를 들어 피벗하이가 감지되면 얼러트가 트리거되는 경우를 살펴봅시다.
pivotHigh 란 특정 수의 이전 및 후속 고점 값보다 큰 값을 갖는 고점입니다. (이 예에서는 이전 및 후속 최고값이 두 개 이상 있습니다.)
다음 파인 스크립트를 써서 위 조건을 충족하는 바를 찾을 수 있습니다:
//@version=6indicator("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)
Java차트에 스크립트를 넣으면 16:30부터 바에 레이블이 표시되지만, pivotHigh 가 왼쪽에서 두 번째 바에 위치하는 것을 볼 수 있습니다.

스크립트에서 alertcondition 에 얼러트를 만들면 16:30부터 바에서 pivotHigh 감지 조건이 충족되므로 16:30부터 바에서도 얼러트가 트리거됩니다.
plotshape 함수에 오프셋을 더해 pivotHigh 바에 레이블을 표시할 수 있습니다.
plotshape(phDetected?high[2]:na, style=shape.labeldown, location=location.absolute, text="pivotHigh", textcolor=color.white, color=color.green, offset=-2)
Java
이러한 오프셋은 편의를 위해서만 필요하며( 다이버전스 인디케이터에서 자주 쓰입니다) 얼러트 트리거에 영향을 미치지 않습니다. 즉, 16:30부터 바에서 얼러트가 여전히 올바르게 트리거됩니다. 그러나 더 일찍(즉, 14:30부터 바에서) 트리거되어야 하는 것처럼 보일 수 있습니다