首页 > 解决方案 > 如何将 Pivot Points H/L 与 TradingView Pine 中的一条线连接起来?

问题描述

我发现枢轴 H/L 的脚本如下所示:

在此处输入图像描述

但我希望 H 和 L 用一条线连接,如下所示:

在此处输入图像描述

这是脚本:

study(title="Pivot Points H/L", shorttitle="Pivots H/L", overlay=true)
len = input(14, minval=1, title="Length")
    //The length defines how many periods a high or low must hold to be a "relevant pivot"

h = highest(len)
    //The highest high over the length
h1 = dev(h, len) ? na : h
    //h1 is a pivot of h if it holds for the full length
hpivot = fixnan(h1)
    //creates a series which is equal to the last pivot

l = lowest(len)
l1 = dev(l, len) ? na : l
lpivot = fixnan(l1)
    //repeated for lows

plot(hpivot, color=blue, linewidth=2, offset= -len+1)
plot(lpivot, color=purple, linewidth=2, offset= -len+1)
//plot(h1, color=black, style=circles, linewidth=4, offset= -len+1)
//plot(l1, color=black, style=circles, linewidth=4, offset= -len+1)

谢谢你。

标签: pine-script

解决方案


无需深入研究代码,您就可以使用 pine 代码生成第二张图片。

您应该在一个变量中记录高点,并在另一个变量中记录枢轴处于活动状态的信号。当枢轴活动代码触发时,您可以使用偏移量进行绘图。

假设您正在寻找价值较低的 2 根右蜡烛的价格支点。在 2 根蜡烛之后,您将收到信号,表明之前有 2 根蜡烛,您有您的支点,然后您应该执行以下操作:

plot(is_pivoth ? pivot_high_price : na, location=location.absolute, offset=-2)

推荐阅读