如何绕过 "if" 运算符限制并绘制 "hline"

How to bypass "if" operator restriction and draw "hline"

尝试在我的基准值上方和下方绘制(并在它们之间切换)三行。但我无法让它工作,因为“if”运算符无法使用“line”。试图在“情节”中引用“hline”——也失败了。对于如何解决此限制,我将不胜感激。 https://i.stack.imgur.com/3k5qk.png

//@version=5
indicator("Lines", overlay=true)
base = input.float(title="Base Value", defval=0.76,  step=0.0001)
lineChoice = input.string(title="Buy/Sell", defval = "Buy", options = ["Buy", "Sell", "Buy&Sell"])

if (lineChoice == "Buy")
    hline(base, title='Base', color=color.aqua, linestyle=hline.style_solid, linewidth=2)
    hline(base * 1.03, title='3%', color=color.aqua, linestyle=hline.style_dotted, linewidth=2)
    hline(base * 1.02, title='2%', color=color.aqua, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 1.01, title='1%', color=color.aqua, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 1.004, title='0,4%', color=color.aqua, linestyle=hline.style_dashed, linewidth=2)
else if (lineChoice =="Sell")    
    hline(base, title='Base', color=color.purple, linestyle=hline.style_solid, linewidth=2)
    hline(base * 0.996, title='-0.4%', color=color.purple, linestyle=hline.style_dotted, linewidth=2)
    hline(base * 0.99, title='-1%', color=color.purple, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 0.98, title='-2%', color=color.purple, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 0.97, title='-3%', color=color.purple, linestyle=hline.style_dashed, linewidth=2)
else if (lineChoice == "Buy&Sell")
    hline(base * 1.03, title='3%', color=color.aqua, linestyle=hline.style_dotted, linewidth=2)
    hline(base * 1.02, title='2%', color=color.aqua, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 1.01, title='1%', color=color.aqua, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 1.004, title='0,4%', color=color.aqua, linestyle=hline.style_dashed, linewidth=2)
    hline(base, title='Base', color=color.red, linestyle=hline.style_solid, linewidth=2)
    hline(base * 0.996, title='-0.4%', color=color.purple, linestyle=hline.style_dotted, linewidth=2)
    hline(base * 0.99, title='-1%', color=color.purple, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 0.98, title='-2%', color=color.purple, linestyle=hline.style_dashed, linewidth=2)
    hline(base * 0.97, title='-3%', color=color.purple, linestyle=hline.style_dashed, linewidth=2)
else
    na
    
plot (base)

谢谢!!!

我希望在这里得到答案,但不得不自己寻找解决方案。我们需要使用“line.new”而不是“hline”,这样就解决了所有问题。

// © via15

//@version=5
indicator("Lines", overlay=true)
base = input.float(title="Base Value", defval=0.7162,  step=0.0001)
lineChoice = input.string(title="Buy/Sell", defval = "Buy", options = ["Buy", "Sell", "Buy&Sell"])

if (lineChoice == "Buy")
    a = line.new(x1=bar_index, y1=base, x2=bar_index[1], y2=base, extend=extend.both, color=color.aqua, style=line.style_solid, width=1)
    b = line.new(x1=bar_index, y1=base * 1.004, x2=bar_index[1], y2=base * 1.004, extend=extend.both, color=color.aqua, style=line.style_dotted, width=1)
    c = line.new(x1=bar_index, y1=base * 1.01, x2=bar_index[1], y2=base * 1.01, extend=extend.both, color=color.aqua, style=line.style_dashed, width=1)
    d = line.new(x1=bar_index, y1=base * 1.02, x2=bar_index[1], y2=base * 1.02, extend=extend.both, color=color.aqua, style=line.style_dashed, width=1)
    e = line.new(x1=bar_index, y1=base * 1.03, x2=bar_index[1], y2=base * 1.03, extend=extend.both, color=color.aqua, style=line.style_dashed, width=1)
else
    na
if (lineChoice == "Sell")
    f = line.new(x1=bar_index, y1=base, x2=bar_index[1], y2=base, extend=extend.both, color=color.purple, style=line.style_solid, width=1)
    g = line.new(x1=bar_index, y1=base * 0.996, x2=bar_index[1], y2=base * 0.996, extend=extend.both, color=color.purple, style=line.style_dotted, width=1)
    h = line.new(x1=bar_index, y1=base * 0.99, x2=bar_index[1], y2=base * 0.99, extend=extend.both, color=color.purple, style=line.style_dashed, width=1)
    i = line.new(x1=bar_index, y1=base * 0.98, x2=bar_index[1], y2=base * 0.98, extend=extend.both, color=color.purple, style=line.style_dashed, width=1)
    j = line.new(x1=bar_index, y1=base * 0.97, x2=bar_index[1], y2=base * 0.97, extend=extend.both, color=color.purple, style=line.style_dashed, width=1)
else
    na
if (lineChoice == "Buy&Sell")
    a = line.new(x1=bar_index, y1=base, x2=bar_index[1], y2=base, extend=extend.both, color=color.aqua, style=line.style_solid, width=1)
    b = line.new(x1=bar_index, y1=base * 1.004, x2=bar_index[1], y2=base * 1.004, extend=extend.both, color=color.aqua, style=line.style_dotted, width=1)
    c = line.new(x1=bar_index, y1=base * 1.01, x2=bar_index[1], y2=base * 1.01, extend=extend.both, color=color.aqua, style=line.style_dashed, width=1)
    d = line.new(x1=bar_index, y1=base * 1.02, x2=bar_index[1], y2=base * 1.02, extend=extend.both, color=color.aqua, style=line.style_dashed, width=1)
    e = line.new(x1=bar_index, y1=base * 1.03, x2=bar_index[1], y2=base * 1.03, extend=extend.both, color=color.aqua, style=line.style_dashed, width=1)
    g = line.new(x1=bar_index, y1=base * 0.996, x2=bar_index[1], y2=base * 0.996, extend=extend.both, color=color.purple, style=line.style_dotted, width=1)
    h = line.new(x1=bar_index, y1=base * 0.99, x2=bar_index[1], y2=base * 0.99, extend=extend.both, color=color.purple, style=line.style_dashed, width=1)
    i = line.new(x1=bar_index, y1=base * 0.98, x2=bar_index[1], y2=base * 0.98, extend=extend.both, color=color.purple, style=line.style_dashed, width=1)
    j = line.new(x1=bar_index, y1=base * 0.97, x2=bar_index[1], y2=base * 0.97, extend=extend.both, color=color.purple, style=line.style_dashed, width=1)
else
    na