Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

plotting Hline but need argument

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading