[英]Pinescript -Plot happening on every bar, not just highest and lowest
I am trying to have the highest and lowest histogram bars in the last 140 indicated with a plotshape.我试图用 plotshape 表示最后 140 个中的最高和最低直方图条。 My code is working a bit too enthusiastically because it is plotting on every bar instead of just the highest and lowest.
我的代码工作有点过于热情,因为它绘制在每个条上,而不仅仅是最高和最低。
I have played around with it for a while and searched for answers with no success.我已经玩了一段时间并寻找答案但没有成功。 Would love some suggestions please if you have some time to spare.
如果你有空的话,会喜欢一些建议。
Thanks Ali谢谢阿里
study("Oscillator (AO)")
nLengthSlow = input(34, minval=1, title="Length Slow")
nLengthFast = input(5, minval=1, title="Length Fast")
xSMA1_hl2 = sma(hl2, nLengthFast)
xSMA2_hl2 = sma(hl2, nLengthSlow)
//indicator
AOval = xSMA1_hl2 - xSMA2_hl2
// Determine colour
lineColour = (AOval > AOval[1]) and (AOval > 0) ? lime :
(AOval < AOval[1]) and (AOval > 0) ? green :
(AOval > AOval[1]) and (AOval < 0) ? red :
maroon
UPpeak = highest(AOval, 140) and (AOval > 0)
DNpeak = lowest(AOval, 140) and (AOval < 0)
plot(AOval, style=histogram, linewidth=3, color=lineColour)
plotshape(UPpeak, title="UPpeak", text="3", style=shape.circle, location=location.bottom, color=blue, size=size.auto, transp=60)
plotshape(DNpeak, title="DNpeak", text="3", style=shape.circle, location=location.bottom, color=orange, size=size.auto, transp=60)
highest()
and lowest()
functions return series
. highest()
和lowest()
函数返回series
。 You then "and" this result with a condition.然后你用一个条件“和”这个结果。 Which looks like this:
150 and true
.看起来像这样:
150 and true
。 As a result, UPpeak
or DNpeak
variables stay true for some period.因此,
UPpeak
或DNpeak
变量在一段时间内保持真实。
What you can do is, check if the current value of AOval
is equal to the highest/lowest within the last 140 bars.您可以做的是,检查
AOval
的当前值是否等于最后 140 个柱中的最高/最低值。 This way, you would know that that bar at that point is the peak.这样,您就会知道那个点是峰值。
UPpeak = (AOval == highest(AOval, 140)) and (AOval > 0)
DNpeak = (AOval == lowest(AOval, 140)) and (AOval < 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.