Highest High in a Range Pine Script

I am trying to label and change the color of the highest bar in the range. Instead, it paints all bars with the color and does not plot the label on the highest bar but on the last bar?

//@version=5
indicator(title='Label', overlay=true)

highestHigh = ta.highest(high, 20)
lowestLows = ta.lowest(low, 20)

PmeU = if highestHigh
    label.new(bar_index, na, "Highest pirce was: " + str.tostring(highestHigh), color=color.green, textcolor=color.black, style=label.style_label_down, yloc=yloc.abovebar)

label.delete(PmeU[1])

barcolor(highestHigh ? color.blue : na)

1 Answer

ta.highest() returns the highest price within the lookback period. It does not return if the current high is the highest. You need an additional check for that.

Coming to the issue with the label, it is because you always delete the previous one. I don't think you want to delete any label in your case.

//@version=5
indicator(title='Label', overlay=true)

highestHigh = ta.highest(high, 20)
lowestLows = ta.lowest(low, 20)

is_high = high >= highestHigh

PmeU = if is_high
    label.new(bar_index, na, "Highest pirce was: " + str.tostring(highestHigh), color=color.green, textcolor=color.black, style=label.style_label_down, yloc=yloc.abovebar)

barcolor(is_high ? color.blue : na)
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest