[英]Pine script: indicating all time high/low when it occurs
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
:我会在每个新的高/低上使用一个label
,并删除以前的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])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.