I am having trouble figuring out the proper implementation while trying to clean up my code and I found a section that seemed ripe for a For-loop, however, I receive the following error:
Cannot use 'plot' in local scope.
When trying to do the following example:
a = 10
b = 5
for i = 1 to b
j = a * i
plot(highest(j), title="Resistance", color=b, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
My original code is as follows:
a=10
plot(highest(a*1), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*2), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*3), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*4), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*5), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
I ultimately would like to have the number of plots(the b variable) adjustable from say 0 to 20 and thus just writting out all the plot lines doesn't really work.
What is the proper way to implement this in Pine?
Thank you!
Your script draw horizontal lines.
With version 5, you can use line in local scope :
a = 10
b = 5
for i = 1 to b
j = a * i
line.new(bar_index-1, ta.highest(j), bar_index, ta.highest(j), extend=extend.both)
and get a result like that :

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With