Here is my code and I want do this in a simpler way. Since I am new, I don’t know how I can do this in a simpler manner.
// @version=5
// Define indicator name
indicator("Higher Highs and Lower Lows",overlay=true)
// Users input
f_ndays = input(true, title="Previous N Days", inline="#1", group = "Previous highs and lows")
i_ndays = input.int(title="High", defval=1, inline="#1", group = "Previous highs and lows")
i_ndays_l = input.int(title="Low", defval=1, inline="#1", group = "Previous highs and lows")
f_nweeks = input(true, title="Previous N Weeks", inline="#2", group = "Previous highs and lows")
i_nweeks = input.int(title="High", defval=1, inline="#2", group = "Previous highs and lows")
i_nweeks_l = input.int(title="Low", defval=1, inline="#2", group = "Previous highs and lows")
f_nmonths = input(true, title="Previous N Months", inline="#3", group = "Previous highs and lows")
i_nmonths = input.int(title="High", defval=1, inline="#3", group = "Previous highs and lows")
i_nmonths_l = input.int(title="Low", defval=1, inline="#3", group = "Previous highs and lows")
show_labels = input(title="Show Labels?", defval=true, group = "Previous highs and lows")
size_labels = input.string(title="Label font size", defval=size.normal, options = [size.large,size.normal,size.small], group = "Previuous highs and lows")
color_labels = input(title="Label font color", defval=color.black, group = "Previous highs and lows")
label_position = input.int(title="Label Position", defval=0, minval=0, maxval=50,tooltip="When increasing number, labels move right", group = "Previous highs and lows")
// Get High&Low Price
isess = session.regular
t = syminfo.tickerid
igaps = barmerge.gaps_off
ilookaehad = barmerge.lookahead_on
High1 = request.security(t,"D",ta.highest(high,1)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High2 = request.security(t,"D",ta.highest(high,2)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High3 = request.security(t,"D",ta.highest(high,3)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High4 = request.security(t,"D",ta.highest(high,4)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High5 = request.security(t,"D",ta.highest(high,5)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High6 = request.security(t,"D",ta.highest(high,6)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High7 = request.security(t,"D",ta.highest(high,7)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High8 = request.security(t,"D",ta.highest(high,8)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High9 = request.security(t,"D",ta.highest(high,9)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High10 = request.security(t,"D",ta.highest(high,10)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High11 = request.security(t,"D",ta.highest(high,11)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High12 = request.security(t,"D",ta.highest(high,2)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High13 = request.security(t,"D",ta.highest(high,13)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High14 = request.security(t,"D",ta.highest(high,14)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High15 = request.security(t,"D",ta.highest(high,15)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High16 = request.security(t,"D",ta.highest(high,16)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High17 = request.security(t,"D",ta.highest(high,17)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High18 = request.security(t,"D",ta.highest(high,18)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High19 = request.security(t,"D",ta.highest(high,19)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
High20 = request.security(t,"D",ta.highest(high,20)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
HH = High1
if (High2 > HH)
HH := High2
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h2 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h2[1])
if (High3 > HH)
HH := High3
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h3 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h3[1])
if (High4 > HH)
HH := High4
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h4 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h4[1])
if (High5 > HH)
HH := High5
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h5 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h5[1])
if (High6 > HH)
HH := High6
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h6 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h6[1])
if (High7 > HH)
HH := High7
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h7 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h7[1])
if (High8 > HH)
HH := High8
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h8 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h8[1])
if (High9 > HH)
HH := High9
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h9 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h9[1])
if (High10 > HH)
HH := High10
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h10 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h10[1])
if (High11 > HH)
HH := High11
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h11 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h11[1])
if (High12 > HH)
HH := High12
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h12 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h12[1])
if (High13 > HH)
HH := High13
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h13 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h13[1])
if (High14 > HH)
HH := High14
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h14 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h14[1])
if (High15 > HH)
HH := High15
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h15 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h15[1])
if (High16 > HH)
HH := High16
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h16 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h16[1])
if (High17 > HH)
HH := High17
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h17 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h17[1])
if (High18 > HH)
HH := High18
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h18 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h18[1])
if (High19 > HH)
HH := High19
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h19 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h19[1])
if (High20 > HH)
HH := High20
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? HH : na : na, linewidth=2, title = "Higher High", color=color.red,style=plot.style_stepline)
label h20 = label.new(bar_index, HH, "Higher High", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(h20[1])
low1 = request.security(t,"D",ta.lowest(low,1)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low2 = request.security(t,"D",ta.lowest(low,2)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low3 = request.security(t,"D",ta.lowest(low,3)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low4 = request.security(t,"D",ta.lowest(low,4)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low5 = request.security(t,"D",ta.lowest(low,5)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low6 = request.security(t,"D",ta.lowest(low,6)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low7 = request.security(t,"D",ta.lowest(low,7)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low8 = request.security(t,"D",ta.lowest(low,8)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low9 = request.security(t,"D",ta.lowest(low,9)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low10 = request.security(t,"D",ta.lowest(low,10)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low11 = request.security(t,"D",ta.lowest(low,11)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low12 = request.security(t,"D",ta.lowest(low,2)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low13 = request.security(t,"D",ta.lowest(low,13)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low14 = request.security(t,"D",ta.lowest(low,14)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low15 = request.security(t,"D",ta.lowest(low,15)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low16 = request.security(t,"D",ta.lowest(low,16)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low17 = request.security(t,"D",ta.lowest(low,17)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low18 = request.security(t,"D",ta.lowest(low,18)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low19 = request.security(t,"D",ta.lowest(low,19)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
low20 = request.security(t,"D",ta.lowest(low,20)[barstate.isconfirmed ? 0 : 1],gaps=igaps, lookahead=ilookaehad)
LL = low1
if (low2 < LL)
LL := low2
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l2 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l2[1])
if (low3 < LL)
LL := low3
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l3 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l3[1])
if (low4 < LL)
LL := low4
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l4 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l4[1])
if (low5 < LL)
LL := low5
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l5 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l5[1])
if (low6 < LL)
LL := low6
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l6 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l6[1])
if (low7 < LL)
LL := low7
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l7 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l7[1])
if (low8 < LL)
LL := low8
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l8 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l8[1])
if (low9 < LL)
LL := low9
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l9 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l9[1])
if (low10 < LL)
LL := low10
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l10 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l10[1])
if (low11 < LL)
LL := low11
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l11 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l11[1])
if (low12 < LL)
LL := low12
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l12 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l12[1])
if (low13 < LL)
LL := low13
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l13 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l13[1])
if (low14 < LL)
LL := low14
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l14 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l14[1])
if (low15 < LL)
LL := low15
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l15 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l15[1])
if (low16 < LL)
LL := low16
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l16 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l16[1])
if (low17 < LL)
LL := low17
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l17 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l17[1])
if (low18 < LL)
LL := low18
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l18 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l18[1])
if (low19 < LL)
LL := low19
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l19 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l19[1])
if (low20 < LL)
LL := low20
plot(f_ndays ? (timeframe.isintraday or timeframe.isdaily) ? LL : na : na, linewidth=2, title = "lower low", color=color.red,style=plot.style_stepline)
label l20 = label.new(bar_index, LL, "Lower Low", style=label.style_none, textcolor = color_labels, size = size_labels, textalign = text.align_right), label.delete(l20[1])
I have made highs and lows using the code. However, I want to combine this code with some other indicator. Due to large number of symbol calls, this indicator is not fit for combining.
New contributor
uttamkgulshan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.