argumentsmaxpine-script-v5tradingview-apihorizontal-line

How to draw a horizontal line in the indicator pane at the 52-week-maximum value of the line indicator


I try to draw a simple horizontal line in the indicator pane, but this does not work:

var float maxLevel := ta.highest(myseries, 52)
hline(show_maxLevel ? maxLevel : na, "52-Week Max", color=color.red, linestyle=hline.style_solid)

I'm getting the error that 'hline' was called with an argument of 'series float' type, but a 'input float' is expected."

---> So do I have to use plot() instead of hline()?? I only want it to show the max value of the last year, as a simple horizontal line. No variation over time. Can anyone help?


Solution

  • In your case, you need to use the functions line*

    //@version=5
    indicator( title='hline', overlay=true)
    
    var ln_max = line.new(na, na, na, na, extend=extend.left, color=color.orange)
    
    W52 = request.security(syminfo.tickerid, "W", ta.highest(52))
    
    if bar_index > 1
        line.set_xy1(ln_max, bar_index - 1, W52)
        line.set_xy2(ln_max, bar_index, W52)