【问题标题】:Pinescript -Plot happening on every bar, not just highest and lowestPinescript - 情节发生在每个柱上,而不仅仅是最高和最低
【发布时间】:2019-10-23 11:54:18
【问题描述】:

我试图用 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)

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      • 2021-04-21
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2019-04-24
      相关资源
      最近更新 更多