I want to indicate the bar at which the absolute all time high/low occurs. This means that if the previous all time/high low is superseded by a new one, the old one(s) shouldn't be indicated. Using hints from here , I was able to come up with this:
//@version=5
// initialization
indicator(title="test", shorttitle="test", overlay=true)
// functions
allTimetHi(source) =>
var atHi = source
atHi := math.max(atHi, source)
allTimetLo(source) =>
var atLo = source
atLo := math.min(atLo, source)
plotchar(high == allTimetHi(high), title = "title", char = "*", location = location.abovebar, size = size.normal, color = color.lime)
plotchar(low == allTimetLo(low), title = "title", char = "*", location = location.belowbar, size = size.normal, color = color.red)
However, as can been seen from the image below, every local all time high/low is indicated:
Is there a way to achieve the effect that I want?
I would just use a label
on each new high/low, and delete previous label
:
//@version=5
indicator(title="test", shorttitle="test", overlay=true)
var float allTimetHi = 0
var float allTimetLo = 9999999999999999
allTimetHi := math.max(allTimetHi, high)
allTimetLo := math.min(allTimetLo, low)
if high == allTimetHi
highLabel = label.new(bar_index, high, text="Highest High!", style=label.style_label_down, color=color.green)
label.delete(highLabel[1])
if low == allTimetLo
lowLabel = label.new(bar_index, low, text="Lowest Low!", style=label.style_label_up, color=color.red)
label.delete(lowLabel[1])
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.