首页 > 解决方案 > 几个问题: 1. 打开或关闭枢轴高低功能。2.改变标签偏移距离

问题描述

我已经尝试编辑之前的帖子来添加这个问题,但我认为没有人看到它,所以这是一个全新的帖子。

-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 更改为具有选项会引发错误。我想更改它,因为当图表处于自动调整状态时,许多价格低于截止值并且不显示。如果价格标签是默认距离的一小部分,那就太好了。(无论默认是什么,但你会发现)

感谢您的任何提示

标签: plotswitch-statementtogglepine-script

解决方案


将条件排除在函数之外更简单。此外,当您不希望显示时,使用显示/隐藏眼睛图标隐藏指示器会更快。

//@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)

推荐阅读