I would like to get the bar index of the last occurrence of pivothigh so I can use it to plot an indicator starting from that index. Not familiar with pinescript and the references are limited
You can usesr the built-in barssince
function and use the result in the history reference operator []
barssincePhigh = barssince(phigh)
barssincePlow = barssince(plow)
However your pivots trigger after 10 bars by default, add leftbars
value to the barsisnce result to show the high/low pivot:
//@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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.