微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的 TradingView 指标正在使用 line.new() 函数在日线图上添加额外的线

如何解决我的 TradingView 指标正在使用 line.new() 函数在日线图上添加额外的线

我正在尝试在支撑和阻力以及支点上画线。但是,它一直在绘制 2 条线而不是 1 条线。它只在我所看到的日线图及以上图表上这样做。代码

// NOT ALL CODE IS SHOWN

draw_line(ycoor,style)=>
    line.new(x1 = bar_index,y1 = ycoor,x2 = bar_index - 1,y2 = ycoor,extend = extend.both,color = ycoor >= close ? color.new(color.red,10) : color.new(color.lime,10),style = style,width = 1) 
pmh = security(syminfo.tickerid,'M',high)[1] 
pml = security(syminfo.tickerid,low)[1] 
pmc = security(syminfo.tickerid,close)[1] 
 
pdh = security(syminfo.tickerid,'D',high)[1] 
pdl = security(syminfo.tickerid,low)[1] 
pdc = security(syminfo.tickerid,close)[1] 

// this is used for user option in the settings for daily of weekly support and resistance 
alt = tl == 'Daily'

pivot = alt ? ((pdh + pdl + pdc) / 3) : (pwh + pwl + pwc) / 3
//there should be more code here for the supports and resistances but I'm not allowed to show. However it is similar.
// the zones variables are used for calculating supports and resistances

multiplier = alt ? 0.001 : 0.002

// formula for first first support and resistance
r3 = alt ? draw_line((zone3 - (pdc * multiplier)),line.style_solid) : draw_line((zone3 - (pwc * multiplier)),line.style_solid)
s3 = alt ? draw_line((zone3 + (pdc * multiplier)),line.style_solid) : draw_line((zone3 + (pwc * multiplier)),line.style_solid)

This is what it looks like on the Daily chart. There are so many additional lines added.

This is what it is supposed to look like. There should only be **3 zones above and below the pivot (yellow line)

感谢任何帮助。谢谢你。 如果您需要更多信息,请告诉我。

解决方法

您的代码缺少一半的变量并且无法编译。 为防止重复打印行,您应该使用 line.delete 删除前一行或使用 line.set_x(line.set_xy,line.set_x2 等) 函数重新定位。

var line l1 = na
if condition
    line.delete(l1[1])
    l1 := line.new(x,y,x2,y2 ... )

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。