将 pine 脚本版本 4 代码转换为低于 4 的版本?

convert pine script version 4 code to a version below 4?

我从 tradingview 文档中找到了一个枢轴点高低示例,但它不是 运行 我的其他代码,因为我的其他代码是用版本 3 或 2 编写的。更改我的其他代码有点麻烦因为它很长。

所以我的选择是弄清楚如何在版本 4 中使用版本 4 中的枢轴点而不是版本 4。

//@version=4
study("Pivot Points High Low", shorttitle="Pivots HL", overlay=true)


lenH = input(title="Length High", type=input.integer, defval=10, minval=1)
lenL = input(title="Length Low", type=input.integer, defval=10, minval=1)


//if i run the code in version 3, this len below causes problems

fun(src, len, isHigh, _style, _yloc, _color) =>
    p = nz(src[len])
    isFound = true
    for i = 0 to len - 1
        if isHigh and src[i] > p
            isFound := false

        if not isHigh and src[i] < p
            isFound := false

    for i = len + 1 to 2 * len
        if isHigh and src[i] >= p
            isFound := false

        if not isHigh and src[i] <= p
            isFound := false

    if isFound
        label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color)

// good news. i can change the color to white and it will at least look decent even though it loses the arrow point

fun(high, lenH, true, label.style_labeldown, yloc.abovebar, color.lime)
fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.red)

如有任何提示,我们将不胜感激

//@version=3
study("Pivot Points High Low", shorttitle="Pivots HL v3", overlay=true)

lenH = input(title="Length High", defval=10, minval=1)
lenL = input(title="Length Low", defval=10, minval=1)

fun(src, len, isHigh) =>
    p = nz(src[len])
    isFound = true
    for i = 0 to len - 1
        if isHigh and src[i] > p
            isFound := false

        if not isHigh and src[i] < p
            isFound := false

    for i = len + 1 to 2 * len
        if isHigh and src[i] >= p
            isFound := false

        if not isHigh and src[i] <= p
            isFound := false

    return = isFound ? p : na

pivotHi = fun(high, lenH, true)
pivotLo = fun(low, lenL, false)

plotchar(pivotHi, "PivotHi", "—", location.absolute, lime, 0, offset = -lenH, size = size.large)
plotchar(pivotLo, "PivotLo", "—", location.absolute, red, 0, offset = -lenL, size = size.large)