几个问题: 1. 打开或关闭枢轴高位和低位功能。 2.改变标签偏移距离

A couple of questions: 1. toggle pivot high and low function on or off. 2. change the label offset distance

我试过编辑之前的 post 来添加这个问题,但我认为没有人看到它,所以这里有一个全新的 post。

-1。我想关闭和打开蜡烛上方显示的枢轴价格。偶尔只是为了能见度。并且函数的以下更改不会执行任何操作:

//@version=4
study(title="testmajiggy", overlay=true)

// I've defined the switch "pvhl" on for the pivot high low here. 

pvhl = input(true, title="pivot hl on")
lenH = input(title="Length High", type=input.integer, defval=100, minval=1)
lenL = input(title="Length Low", type=input.integer, defval=100, minval=1)

// then put it in as an argument for the function "fun" down here. I'm not sure if I did it right... 

fun(pvhl, src, len, isHigh, _style, _yloc, _color) =>
    pvhl
    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)

//then I made sure the "fun" call included the pvhl argument in here. 

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

pvhl 开关不应该让我选择关闭或打开 fun 功能吗?它让我可以选择打开或关闭,但它什么都不做。

-2。如何更改标签的偏移距离?将 yloc.abovebar 更改为具有选项会引发错误。我想更改它,因为当图表处于自动调整状态时,许多价格都低于截止值并且不显示。如果价格标签是默认距离的一小部分,那就太好了。(无论默认是什么,无论您如何发现)

感谢任何提示

将条件保留在函数之外更简单。此外,当您不想显示时,使用 Show/Hide 眼睛图标隐藏指示器会更快。

//@version=4
study(title="testmajiggy", overlay=true)

pvhl = input(true, title="pivot hl on")
lenH = input(title="Length High", type=input.integer, defval=100, minval=1)
lenL = input(title="Length Low", type=input.integer, defval=100, minval=1)
atrM = input(0.5, "Price Offset (Multiple of ATR)", minval = 0.0, step = 0.1)
atrD = atr(5) * atrM

fun(src, len, isHigh, _style, _yloc, _color, _offset) =>
    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 + _offset, tostring(p), style=_style, yloc=_yloc, color=_color)

if pvhl
    fun(high, lenH, true, label.style_labeldown, yloc.price, color.white, atrD)
    fun(low, lenL, false, label.style_labelup, yloc.price, color.white, -atrD)