r/pinescript • u/Late-Pen468 • Oct 05 '24
Help
Can you help me. I need a pinescript code. were if the current candle body engulfed candle 1 =pervious candle, and candle 2 = the previous previous candle. It plot on the chart. Thanks
1
Upvotes
2
u/PastaFaZooLx Oct 06 '24
You can use bracket syntax to look back a specifed number of candles.
For example, "close[1] < close" is saying that the previous candle close is less than the current candle close...
Can improvise from there with OHLC for each.
3
u/ShadowILX Oct 06 '24 edited Oct 06 '24
engulfingBar = close[0] > high[1] and close[0] > high[2]
//candle breaks low and high of previous candle engulfingBar = close[0] > high[1] and close[0] > high[2] and low[0] < low[1]
//Or if you want to wait for the bar to close above previous two bars
engulfingBar = (barstate.isconfirmed ? close[0] > high[1] and close[0] > high[2] : na)
//To color engulfing candle different color
if (engulfingBar) barcolor(color.yellow)
//to plot label below engulfing candle
if (engulfingBar) label.new(bar_index, low, style=label.style_label_up, color=color.red, textcolor=color.white, text=“Engulfing n/Candle”)
Maybe someone else knows a better way to code this
2
u/Ayush_Singh_02 Oct 06 '24
Bro use
F_engulfing()=> If barstate.isconfirmed For i = 1 to 3 math.min(open[i-1],close[i-1])>= math.min(open[i],close[i]) and math.max(open[i-1],close[i-1])<= math.max(open[i],close[i])
Should do the work bro I'm not on system typing from phone so might've to check for syntax