将中点添加到枢轴高低指示器

Add mid point to pivot high low indicator

嗨 Stack 溢出社区。

我还不是一个优秀的编码员,可能应该做更多的教程,但我发现我通过解决我遇到的问题学到了更多。目前遇到的问题我相信对你们中的许多人来说都是非常基本的,但我已经尝试了一系列的事情,但还是做错了。

目前有以下代码,它只是基本的枢轴点高低指标。我正在尝试标记当前高点和当前低点之间的中点并将其绘制在图表上。我觉得问这个问题很愚蠢,但我只是没有想法。

非常感谢任何帮助,谢谢。

https://www.tradingview.com/x/oqrq4nDj/

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)
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)
fun(high, lenH, true, label.style_labeldown, yloc.abovebar, color.lime)
fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.red) ```
//@version=4
study("Help (Pivot Points High Low) v3", 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)

lastHP = 0.0
lastLP = 0.0
var ln = line.new(na, na, na, na, extend=extend.left)

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)
        p
    else
        float(na)


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

//plot((lastHP + lastLP)/2, offset=-lenH)

line.set_xy1(ln, bar_index[1], (lastHP + lastLP)/2)
line.set_xy2(ln, bar_index[0], (lastHP + lastLP)/2)