wahab Mohmadsharif
wahab Mohmadsharif

Reputation: 41

How can i draw the horizontal lines on pine script for particular candle?

//@version=4
//@WMSIDI

study(title = "Engulfing Lines", overlay = true)

// bullish engulfing (alpha)
alpha = open[3] > close[3] ? open[2] > close[2] ? open[1] > close[1] ? close > open ? close >=open[1] ? close[1] >= open ? close - open > open[1] - close[1] ? color.yellow :na :na : na : na : na :na :na

barcolor(alpha)

plot(close, "Line", color.lime, 2, plot.style_line, true, show_last=1)
plot(open, "Line", color.blue, 2, plot.style_line, true, show_last=1)

enter image description here

I have added the image that is generated after running this script for bullish engulfing candle. I wanna draw horizontal lines on open and close of each detected bullish engulfing candle. How can we do that?

Upvotes: 0

Views: 1516

Answers (1)

vitruvius
vitruvius

Reputation: 21332

You can use the line feature for that. There are some limitations.

//@version=4
//@WMSIDI

study(title = "Engulfing Lines", overlay = true)

// bullish engulfing (alpha)
eng = open[3] > close[3] and open[2] > close[2] and open[1] > close[1] and close > open and close >=open[1] and close[1] >= open and close - open > open[1] - close[1]
alpha = eng ? color.yellow :na

barcolor(alpha)

var line l_close = na
var line l_open = na
l_close_level = close
l_open_level = open

if eng
    line.set_x2(l_close, bar_index)
    line.set_extend(l_close, extend.none)
    line.set_x2(l_open, bar_index)
    line.set_extend(l_open, extend.none)
    l_close := line.new(bar_index, l_close_level, bar_index, l_close_level, extend=extend.right, width=2)
    l_open := line.new(bar_index, l_open_level, bar_index, l_open_level, extend=extend.right, width=2)

enter image description here

Upvotes: 1

Related Questions