1

我目前正在尝试为 TradingView 编写 Pine Script 中的脚本,并且在绘制仅在最后收盘价/时间和图表末尾之间绘制的水平线时遇到了困难。附图片供参考。关联

我目前正在尝试使用 line.set 和 line.new 以便我可以接受自定义价格输入并将语句放入 if 函数中。

任何有助于实现这一目标的帮助将不胜感激。

此处附有代码,可选择在整个图表上画一条线或仅如上所示。

show1 = input(true, title="|- Use Line1?")
dS1 = input(true, title="|- Short Line1")
price1 = input(title="Price1", type=input.integer, defval=0)

var line l1 = na
if show1 
    line.set_x2(l1, bar_index)
    line.set_extend(l1, extend.none)
    line.set_color(l1, color.green)
    line.set_style(l1, line.style_solid)
    line.set_width(l1, 2)
    if dS1
        l1 := line.new(bar_index, price1, bar_index, price1, extend=extend.right)
    else
        l1 := line.new(bar_index, price1, bar_index, price1, extend=extend.both)

    label label1 = label.new(bar_index, price1, "Line1", textcolor=color.green, style=label.style_none), label.delete(label1[1])
4

1 回答 1

1

原始代码有一些问题,包括:

  • 覆盖延伸到无
  • 不删除之前打印的行(就像标签一样)

这将做你正在寻找的一个警告(它从上一个栏中提取)。从当前栏中绘制它稍微有点棘手。

//@version=4
study("Line Example [MS]", overlay=true)

show1 = input(true, title="|- Use Line1?")
dS1 = input(true, title="|- Short Line1")
price1 = close

var line l1 = na
if show1 
    l1 := line.new(bar_index[1], price1, bar_index, price1, color=color.red, style=line.style_solid, width=2, extend=dS1 ? extend.right : extend.both)
    label label1 = label.new(bar_index, price1, "Line1", textcolor=color.green, style=label.style_none)
    
    line.delete(l1[1])
    label.delete(label1[1])

我建议在 line.new 上阅读更多内容:https ://marketscripters.com/how-to-use-pine-scripts-v4-line-function/

于 2020-08-18T21:26:21.867 回答