Search code examples
pine-scriptpine-script-v5

How to make the variable price - 500, formed not as a curve, but as a horizontal line with coordinates (price - 500)


Demonstration of the problem

I don't know how to get the horizontal line when using the calculations for the variable. Please see the attached picture.Moreover, it is the variable that is needed, and not the output of data through the plot function.

//@version=5
indicator(title="intersection", shorttitle="INTR",overlay = true, max_bars_back = 100)

a = 44626
plot(a, '1', color = color.white)
//How can I make it so that during calculations I get not a curve but a horizontal line? those. when calculating the output, not the curve a1, but a.
a1 = close - 1000
plot(a1, '1', color = color.red)

Solution

  • Two ways to do that. Using an hline or a line.new

    //@version=5
    indicator(title="intersection", shorttitle="INTR",overlay = true, max_bars_back = 100)
    
    a = 44626
    plot(a, '1', color = color.blue)
    //How can I make it so that during calculations I get not a curve but a horizontal line? those. when calculating the output, not the curve a1, but a.
    a1 = close - 1000
    plot(a1, '1', color = color.red)
    // hline way
    hline(a,'A HLine', color.blue)
    //line.new way
    if barstate.islast
        line.new(bar_index, a1, bar_index + 1, a1, extend = extend.both)