I have created a multi Zig Zag indicator, and can't figure out how to allow the user to toggle each Zig Zag line on/off.
Here is the code...
//@version=5
indicator('Multi Structure Zig Zag', max_lines_count=500)
length = input(100, title='Structure HTF')
h = ta.highest(high, length * 2 + 1)
l = ta.lowest(low, length * 2 + 1)
f_isMin(len) =>
l == low[len]
f_isMax(len) =>
h == high[len]
var dirUp = false
var lastLow = high * 100
var lastHigh = 0.0
var timeLow = bar_index
var timeHigh = bar_index
var line li = na
f_drawLine() =>
_li_color = dirUp ? color.rgb(89, 42, 34, 6) : color.rgb(89, 42, 34, 6)
line.new(timeHigh - length, lastHigh, timeLow - length, lastLow, xloc.bar_index, color =_li_color, width=2)
if dirUp
if f_isMin(length) and low[length] < lastLow
lastLow := low[length]
timeLow := bar_index
line.delete(li)
li := f_drawLine()
li
if f_isMax(length) and high[length] > lastLow
lastHigh := high[length]
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li
if not dirUp
if f_isMax(length) and high[length] > lastHigh
lastHigh := high[length]
timeHigh := bar_index
line.delete(li)
li := f_drawLine()
li
if f_isMin(length) and low[length] < lastHigh
lastLow := low[length]
timeLow := bar_index
dirUp := true
li := f_drawLine()
if f_isMax(length) and high[length] > lastLow
lastHigh := high[length]
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li
//length 2
length2 = input(50, title='Structure MTF')
h2 = ta.highest(high, length2 * 2 + 1)
l2 = ta.lowest(low, length2 * 2 + 1)
f_isMin2(len2) =>
l2 == low[len2]
f_isMax2(len2) =>
h2 == high[len2]
var dirUp2 = false
var lastLow2 = high * 100
var lastHigh2 = 0.0
var timeLow2 = bar_index
var timeHigh2 = bar_index
var line li2 = na
f_drawLine2() =>
_li_color2 = dirUp2 ? color.rgb(52, 8, 247) : color.rgb(52, 8, 247)
line.new(timeHigh2 - length2, lastHigh2, timeLow2 - length2, lastLow2, xloc.bar_index, color=_li_color2, width=2, style=line.style_dashed)
if dirUp2
if f_isMin2(length2) and low[length2] < lastLow2
lastLow2 := low[length2]
timeLow2 := bar_index
line.delete(li2)
li2 := f_drawLine2()
li2
if f_isMax2(length2) and high[length2] > lastLow2
lastHigh2 := high[length2]
timeHigh2 := bar_index
dirUp2 := false
li2 := f_drawLine2()
li2
if not dirUp2
if f_isMax2(length2) and high[length2] > lastHigh2
lastHigh2 := high[length2]
timeHigh2 := bar_index
line.delete(li2)
li2 := f_drawLine2()
li2
if f_isMin2(length2) and low[length2] < lastHigh2
lastLow2 := low[length2]
timeLow2 := bar_index
dirUp2 := true
li2 := f_drawLine2()
if f_isMax2(length2) and high[length2] > lastLow2
lastHigh2 := high[length2]
timeHigh2 := bar_index
dirUp2 := false
li2 := f_drawLine2()
li2
//length 3
length3 = input(10, title='Structure LTF')
h3 = ta.highest(high, length3 * 2 + 1)
l3 = ta.lowest(low, length3 * 2 + 1)
f_isMin3(len3) =>
l3 == low[len3]
f_isMax3(len3) =>
h3 == high[len3]
var dirUp3 = false
var lastLow3 = high * 100
var lastHigh3 = 0.0
var timeLow3 = bar_index
var timeHigh3 = bar_index
var line li3 = na
f_drawLine3() =>
_li_color3 = dirUp3 ? color.rgb(166, 0, 255) : color.rgb(166, 0, 255)
line.new(timeHigh3 - length3, lastHigh3, timeLow3 - length3, lastLow3, xloc.bar_index, color=_li_color3, width=2, style=line.style_dotted)
if dirUp3
if f_isMin3(length3) and low[length3] < lastLow3
lastLow3 := low[length3]
timeLow3 := bar_index
line.delete(li3)
li3 := f_drawLine3()
li3
if f_isMax3(length3) and high[length3] > lastLow3
lastHigh3 := high[length3]
timeHigh3 := bar_index
dirUp3 := false
li3 := f_drawLine3()
li3
if not dirUp3
if f_isMax3(length3) and high[length3] > lastHigh3
lastHigh3 := high[length3]
timeHigh3 := bar_index
line.delete(li3)
li3 := f_drawLine3()
li3
if f_isMin3(length3) and low[length3] < lastHigh3
lastLow3 := low[length3]
timeLow3 := bar_index
dirUp3 := true
li3 := f_drawLine3()
if f_isMax3(length3) and high[length3] > lastLow3
lastHigh3 := high[length3]
timeHigh3 := bar_index
dirUp3 := false
li3 := f_drawLine3()
li3
I've tried everything I can think of but can't seem to come up with a solution. The only option is settings is "Lines" checked On or Off, but there doesn't seem to be an easy way to separate them individually. Any help would be much appreciated