Pine script pinescript获取pivothigh的索引

Pine script pinescript获取pivothigh的索引,pine-script,trading,Pine Script,Trading,我想得到pivothigh最后一次出现的条形索引,这样我就可以用它来绘制一个从该索引开始的指示器,但似乎无法让它工作 study("Pivot Prices", overlay=true) leftbars = input(10, minval=1, title='Bars to the left') rightbars = input(10, minval=1, title='Bars to the right') phigh = pivothigh(high, lef

我想得到pivothigh最后一次出现的条形索引,这样我就可以用它来绘制一个从该索引开始的指示器,但似乎无法让它工作

study("Pivot Prices", overlay=true)

leftbars = input(10, minval=1, title='Bars to the left')
rightbars = input(10, minval=1, title='Bars to the right')

phigh = pivothigh(high, leftbars, rightbars)
plow = pivotlow(low, leftbars, rightbars)

if phigh
    label1 = label.new(bar_index[rightbars], high[rightbars], text=tostring(high[rightbars]), style = label.style_labeldown, color = color.orange)

if plow
    label2 = label.new(bar_index[rightbars], low[rightbars], text=tostring(low[rightbars]), style = label.style_labelup, color = color.green).

如果有人能告诉我如何将发生枢轴的所有索引保存为一个数组,这样我就可以访问它们,那也太好了。例如,定义了一个pivot数组,如果我使用pivot[0],它将返回15(例如),对应于最近一个pivot的条索引。

您可以使用内置的
barssince
函数,并在历史引用操作符
[]

barssincePhigh = barssince(phigh)
barssincePlow = barssince(plow)
但是,默认情况下,枢轴在10条后触发,请将
leftbars
值添加到barsisnce结果以显示高/低枢轴:

//@version=4
study("Pivot Prices", overlay=true)

leftbars = input(10, minval=1, title='Bars to the left')
rightbars = input(10, minval=1, title='Bars to the right')

phigh = pivothigh(high, leftbars, rightbars)
plow = pivotlow(low, leftbars, rightbars)

barssincePhigh = barssince(phigh) + leftbars
barssincePlow = barssince(plow) + leftbars

if phigh
    label1 = label.new(bar_index[barssincePhigh], high[barssincePhigh], text=tostring(high[barssincePhigh]), style = label.style_labeldown, color = color.orange)

if plow
    label2 = label.new(bar_index[barssincePlow], low[barssincePlow], text=tostring(low[barssincePlow]), style = label.style_labelup, color = color.green)