使用偏移量指標的快訊問題

如果在使用帶有偏移量的繪圖的指標上創建快訊,那麼在比較快訊訊號與圖表訊號時,可能會感覺到快訊有延遲觸發的情況。

讓我們來看一個例子:當偵測到 pivotHigh 時,觸發快訊。

pivotHigh 是指其數值大於一定數量的前後高點的高點。(在此範例中,前後高點的數量超過兩個。)

您可以使用以下 Pine Script 來找到符合上述條件的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)
  

將腳本增加到圖表後,我們會看到頁籤顯示在 16:30 的K線上,儘管 pivotHigh 實際上位於左側的兩根K線處。 

如果您在腳本中使用 alertcondition 創建快訊,該快訊也會在 16:30 的K線上觸發,因為該K線滿足 pivotHigh 的偵測條件。 

我們可以在 plotshape 函數中增加偏移量,以在 pivotHigh 所在的K線上顯示頁籤。 

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

這種偏移僅是為了方便(在背離指標中經常使用),並不影響快訊的觸發。換句話說,快訊仍會在 16:30 的K線上正確觸發。然而,可能會產生一種錯覺,認為快訊應該更早觸發(即在 14:30 的K線上)。