【问题标题】:How to plot a hline with closing price of latest candle using pine script?如何使用 pine 脚本绘制具有最新蜡烛收盘价的 hline?
【发布时间】:2021-06-04 04:37:01
【问题描述】:

如何使用 pine 脚本绘制带有最新蜡烛收盘价的hline?如果我将 close 作为输入提供给hline,则会出现以下错误:

study("CP-ATR",overlay=true)
cpatr = close-atr(14)
plot(cpatr)
hline(close, title="Zero", color=color.gray, linestyle=hline.style_dashed)

第 8 行:不能使用参数调用“hline”(series[float]、title=literal string、color=const color、linestyle=const integer);可用重载:hline(input float, const string, input color, input integer, input integer, const bool, string) => hline

【问题讨论】:

  • 我遇到了同样的问题。据我所知,没有办法将 series[float] 转换为 float。但是,您可以将其转换为字符串,并且当这样做时,我可以看到有问题的变量是一个完全合理的数字, hline 应该能够接受。但是因为您不能将 series[float] 转换为 float,尽管该系列中只有一个对象,我认为这是不可能的。 :(

标签: pine-script


【解决方案1】:

hline 函数不接受序列作为源,只接受常量/输入。

要从紧密系列中绘制一条水平线,您可以尝试plot 函数并定义trackpriceshow_last 参数,如下例所示:

//@version=4
study("CP-ATR",overlay=true) 
cpatr = close-atr(14) 
plot(cpatr) 
plot(close, title="Zero", color=color.gray, trackprice = true, show_last = 1) 

【讨论】:

  • 我不想绘制一系列数据,我想在收盘价处绘制一条水平线 - 最新每日蜡烛的 ATR。
【解决方案2】:

使用line.new() 函数。

//@version=4
study("Help (CP-ATR)", overlay=true)
cpatr = close-atr(14)
plot(cpatr)
//hline(close, title="Zero", color=color.gray, linestyle=hline.style_dashed)

line ln = na
line.delete(ln[1])
ln := line.new(bar_index - 1, cpatr, bar_index, cpatr, width=2, color=color.gray, extend=extend.both, style=line.style_dashed) 

【讨论】:

    【解决方案3】:

    如果您查看电视如何提供频道,例如 Keltner Channels,您会发现他们正在使用绘图功能将系列转换为常量/整数/浮点数。

    这里有一个解决方法。它没有显示一条线,但它可以满足您的需求。

    cpatr = close-atr(14)
    h=plot(cpatr)
    fill(h,h, title="Zero", color=color.gray)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      相关资源
      最近更新 更多