So I need an argument for if that triggers every 20 new bars. As you can see I have the code ready, but for some dumb reason, I can’t figure out how to trigger it every 20 new bars.
//Input options
highlength = input.int(20, "High Length")
lowlength = input.int(20, "Low Length")
Tah = ta.highest(highlength)
Tal = ta.lowest(lowlength)
//color fill
var highhighs = float(na)
var lowlows = float(na)
var line Linehighhighs = na
var line Linelowlows = na
if 'every 20 new bars i want to plot a line with the highest and lowest values'
highhighs := Tah
lowlows := Tal
Linehighhighs := line.new(bar_index, highhighs, bar_index, highhighs, color = color.white, width = 2)
Linelowlows := line.new(bar_index, lowlows, bar_index, lowlows, color = color.white, width = 2)
else
line.set_x2(Linehighhighs, bar_index)
line.set_x2(Linelowlows, bar_index)
I really appreciate any help you can provide.
>Solution :
Using the Modulo Operator %
on bar_index
and comparing the reminder to 0 will trigger the condition every 20 bars:
if bar_index % 20 == 0
highhighs := Tah
lowlows := Tal
Linehighhighs := line.new(bar_index, highhighs, bar_index, highhighs, color = color.white, width = 2)
Linelowlows := line.new(bar_index, lowlows, bar_index, lowlows, color = color.white, width = 2)
else
line.set_x2(Linehighhighs, bar_index)
line.set_x2(Linelowlows, bar_index)