使用偏移量的指标警报问题

如果在使用带偏移的图的指标上创建警报,那么当将警报信号与图表上的信号进行比较时,警报似乎会延迟触发。

让我们看一个例子:检测到pivotHigh时触发的警报。

pivotHigh是一个高点,其值大于一定数量的前一个和后续高值。(此示例中有两个以上的前一个和后续高值。)

您可以使用此Pine脚本找到满足上述条件的K线:

//@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)
  
Java

当将脚本添加到图表时,我们看到标签显示在16:30的K线,尽管pivotHigh位于左侧2根K线上。

如果您从脚本中创建警报条件警报,它也将从16:30开始在K线触发,因为该K线满足pivotHigh检测条件。

我们可以向plotshape函数添加偏移量以在pivotHighK线显示标签。

plotshape(phDetected?high[2]:na, style=shape.labeldown, location=location.absolute, text="pivotHigh", textcolor=color.white,  color=color.green, offset=-2)
  
Java

这样的偏移只是为了方便(它经常用于背离指标),并不影响警报触发,也就是说,警报仍将在16:30开始的K线正确触发。但是,它似乎应该更早触发(即在14:30开始的K线)。