Pinescript - 情节发生在每个柱子上,而不仅仅是最高和最低

Pinescript -Plot happening on every bar, not just highest and lowest

我正在尝试用 plotshape 表示最后 140 个中最高和最低的直方图条。 我的代码有点太热情了,因为它在每个柱上绘制,而不仅仅是最高和最低。

我已经玩了一段时间并搜索了没有成功的答案。如果您有空闲时间,希望得到一些建议。

谢谢 阿里

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()lowest() 函数 return series。然后你 "and" 这个结果带有一个条件。看起来像这样:150 and true。因此,UPpeakDNpeak 变量在一段时间内保持为真。

您可以做的是,检查 AOval 的当前值是否 等于 最近 140 根柱中的 highest/lowest 。这样,您就会知道该点的柱线是峰值。

UPpeak = (AOval == highest(AOval, 140)) and (AOval > 0)
DNpeak = (AOval == lowest(AOval, 140)) and (AOval < 0)