// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tista
//@version=4
study("Engulfing Candles", overlay=true)
useEmaAsConfirmation = input(true, title="Use EMA As Confirmation?", defval=false)
showEma = input(false, title="Show EMA Line?", defval=false)
emaPeriod = input(200, title="EMA Period (Surpress noise with higher EMA periods)", defval=200)
emaVals = ema(close, emaPeriod)
isBullishEngulfing = open[1] > close[1] and open >= close[1] and open <= close[1] and close >= open[1] and (useEmaAsConfirmation ? close <= emaVals : true)
isBearishEngulfing = open[1] < close[1] and open <= close[1] and open >= close[1] and close <= open[1] and (useEmaAsConfirmation ? close >= emaVals : true)
vals = isBullishEngulfing ? 1 : isBearishEngulfing ? -1 : na
// plotbar(open, high, low, close, title="Engulfing Candle", color = colors)
plotarrow(vals, title="Engulfing Candles", colorup=color.teal, colordown=color.orange, transp=40, maxheight=15)
plot(emaVals, title="EMA", color=showEma ? color.yellow : na, linewidth=2, transp=0)