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

Horizontal lines failing to plot

How can I draw a horizontal line at the price level when my condition is triggered ? (version#4)

plotshape(crossUp_red ? rvi : na, title="Up Arrow", style=shape.arrowup, location=location.abovebar, color=#109c3f, size=size.small, text="crossUp_red") // plots arrow

However I’m having trouble plotting a line at the price where ‘crossUp_red’ is triggered.

trigger_price = valuewhen(crossUp_red, close, 0)
plot(trigger_price, title="line_crossUp_red", color=color.green, linewidth=2, transp=0)

Draws line/all lines, but amassed at the bottom of the chart.

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

trigger_price = valuewhen(crossUp_red, close, 0)
hline(trigger_price, title="Trigger Price", color=color.red, linestyle=hline.style_dotted)

Error: Cannot call ‘hline’ with ‘price’=series[float]. The argument should be of type: input float

Many thanks.

>Solution :

You can use line.new() for this.

if (crossUp_red)
    red_line = line.new(bar_index, rvi, bar_index + 1, rvi, extend=extend.right)

This will draw a line and extend it to the right whenever crossUp_red is true. The line will be at rvi‘s value. I don’t know if it is price or not. If you want, you can change rvi to close then it would draw it at that bar’s close price.

If you want to delete some lines in the future, you can use the line.delete() function.

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