标记闭合线等于特定水平线的闭合线

问题描述 投票:1回答:1

我已经尝试了许多不同的方法,并且使用line.new和line.get这个方法是我得到的最接近的方法。如果我可以调整此方法很好,或者有完全不同的方法也可以。谢谢。

目标是将最近200条的收盘价与最近的收盘价进行比较(不是实时条,而是最新的历史条)。我要突出显示所有收盘价等于最近收盘价的柱线。在所附的图片中,您可以看到实时栏标记为b / c,它的关闭当前符合标准(但我不在乎那个),但是还应该标记其他几个栏(请参阅我绘制的箭头)手动),因为它们的收盘价与最近的收盘价相等。

study("t1t2_020920", overlay=true)

CloseLineFunc() =>
    if (barstate.islast)
        closeline = line.new(bar_index[200],close[1],bar_index[1],close[1])
        closeline

CloseLineFunc()
a=CloseLineFunc()

x1 = line.get_x1(a)  // Returns UNIX time or bar index (depending on the last xloc value set) of the first point of the line
x2 = line.get_x2(a) // Returns UNIX time or bar index (depending on the last xloc value set) of the second point of the line
y1 = line.get_y1(a) // Returns price of the first point of the line
y2 = line.get_y2(a) // Returns price of the second point of the line

// plot(x1)
// plot(x2)
// plot(y1)
// plot(y2)


check = close == y2
plotchar(check, char='*', color=color.green, size=size.normal)

``enter image description here

我也认为这会起作用,但是我没有结果。棘手的部分是,在图表左侧的计算中,要弄清楚如何使用最近的收盘价(不包括实时柱线)的值,然后每次打印新的柱线时都以这种方式重新计算研究。

study("My Script", overlay=true)

lineprice = valuewhen(barstate.islast,close[1],0)

plot(lineprice)

check = sma(close,1) == lineprice
plotchar(check, char='*', color=color.green, size=size.normal)``
pine-script
1个回答
0
投票

我认为,应该像这样:

//@version=4
study("My Script", overlay=true)

MAX_LABELS = 40
if barstate.islast
    labersNum = 0
    for i = 1 to 4999
        if close[i] == close
            label.new(time[i], high[i], xloc=xloc.bar_time, yloc=yloc.abovebar, style=label.style_arrowdown)
            labersNum := labersNum + 1
            if labersNum >= MAX_LABELS
                break

应该对脚本进行调整,以支持最后的非实时条形,如果有新的条形,则可以更改标签,但是我觉得这个脚本足以开始。

© www.soinside.com 2019 - 2024. All rights reserved.