Pinescript-绘制发生在每个柱上,而不仅是最高和最低

时间:2019-10-23 11:54:18

标签: pine-script

我试图在最近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)

1 个答案:

答案 0 :(得分:2)

highest()lowest()函数返回series。然后,您将这个结果与条件“和”。看起来像这样:150 and true。结果,UPpeakDNpeak变量在一段时间内保持为真。

您可以做的是,检查AOval的当前值是否等于等于最后140条之内的最高/最低值。这样,您会知道那个点的那个柱是峰值。

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

enter image description here