【问题标题】:Pine Script Drawing a horizontal line to the right of barsPine 脚本在条的右侧绘制一条水平线
【发布时间】:2020-08-15 19:17:44
【问题描述】:

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

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

【问题讨论】:

  • 这里的答案通常是代码修复,因此它们需要代码。你试过什么代码?
  • 用我的代码编辑了我的帖子。谢谢:)

标签: pine-script horizontal-line


【解决方案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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 2020-07-03
    • 1970-01-01
    • 2022-01-21
    • 2017-03-29
    • 1970-01-01
    相关资源
    最近更新 更多