我的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, 'M', low)[1] 
pmc = security(syminfo.tickerid, 'M', close)[1] 

pdh = security(syminfo.tickerid, 'D', high)[1] 
pdl = security(syminfo.tickerid, 'D', low)[1] 
pdc = security(syminfo.tickerid, 'D', 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)

这就是它在每日图表上的样子。添加了许多附加行。

这就是它应该有的样子。枢轴(黄线(上方和下方应该只有**3个区域

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

您的代码缺少一半的变量,并且不可编译。为防止重复打印行,应使用line.delete删除前一行,或使用line.set_x(line.set_xyline.set_x2等(功能重新定位位置。

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

最新更新