Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pine script 在条形图右侧绘制水平线的松树脚本_Pine Script_Horizontal Line - Fatal编程技术网

Pine script 在条形图右侧绘制水平线的松树脚本

Pine script 在条形图右侧绘制水平线的松树脚本,pine-script,horizontal-line,Pine Script,Horizontal Line,我目前正试图用Pine script为TradingView编写一个脚本,但我很难画出一条水平线,只在最后收盘价/时间和图表末尾之间绘制。附图片供参考 我目前正在尝试使用line.set和line.new,这样我就可以接受自定义的价格输入,并将语句放入if函数中 任何帮助都将不胜感激 此处附加代码,可选择在整个图表上画一条线或仅如上所述 show1 = input(true, title="|- Use Line1?") dS1 = input(true, title=&qu

我目前正试图用Pine script为TradingView编写一个脚本,但我很难画出一条水平线,只在最后收盘价/时间和图表末尾之间绘制。附图片供参考

我目前正在尝试使用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])

原始代码有几个问题,包括:

  • 覆盖扩展为无
  • 不删除以前打印的线条(如标签)
这将满足您的需求,但需要注意一点(它从上一条中提取)。从当前栏中绘制它要稍微复杂一些

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


我建议在线阅读更多内容。新增:

这里的答案通常是代码修复,因此需要代码。你尝试了什么代码?用我的代码编辑了我的文章。谢谢:)