OPEN-SOURCE SCRIPT
My script

/version=5
indicator("dvp - Engulfing Strategy", overlay=true)
// Moving Averages
sma1 = input.int(6,"Trend SMA")
ema1 = input.int(3,"Engulf EMA")
sma6 = ta.sma(close, sma1)
ema3 = ta.ema(close, ema1)
// Helper candles
c3 = close[2] < open[2] // 3 days ago was a red candle
c2 = close[1] > open[1] // 2 days ago was a green candle
engulfed = (low[1] < low[2]) and (high[1] > high[2]) // bullish engulfing
c0_bull = close > open // current candle is green
close_above_c2high = close > high[1]
c3_below_sma6 = close[2] < sma6[2]
c0_above_ema3 = close > ema3
// Bullish Engulfing Conditions
bullishSignal = c3 and c2 and engulfed and c0_bull and close_above_c2high and c3_below_sma6 and c0_above_ema3
// Plotting text for bullish engulfing
plotshape(bullishSignal, title="Bullish Engulfing", location=location.belowbar, color=color.green, style=shape.labelup, text="BuE")
// Optional: Bearish Engulfing Detection
c3_bear = close[2] > open[2] // 3 days ago green
c2_bear = close[1] < open[1] // 2 days ago red
engulfed_bear = (high[1] > high[2]) and (low[1] < low[2])
c0_bear = close < open // current red
close_below_c2low = close < low[1]
c3_above_sma6 = close[2] > sma6[2]
c0_below_ema3 = close < ema3
bearishSignal = c3_bear and c2_bear and engulfed_bear and c0_bear and close_below_c2low and c3_above_sma6 and c0_below_ema3
plotshape(bearishSignal, title="Bearish Engulfing", location=location.abovebar, color=color.red, style=shape.labeldown, text="BeU")
// Plotting Moving Averages
plot(sma6, color=color.orange, title="SMA 6")
plot(ema3, color=color.blue, title="EMA 3")
```
indicator("dvp - Engulfing Strategy", overlay=true)
// Moving Averages
sma1 = input.int(6,"Trend SMA")
ema1 = input.int(3,"Engulf EMA")
sma6 = ta.sma(close, sma1)
ema3 = ta.ema(close, ema1)
// Helper candles
c3 = close[2] < open[2] // 3 days ago was a red candle
c2 = close[1] > open[1] // 2 days ago was a green candle
engulfed = (low[1] < low[2]) and (high[1] > high[2]) // bullish engulfing
c0_bull = close > open // current candle is green
close_above_c2high = close > high[1]
c3_below_sma6 = close[2] < sma6[2]
c0_above_ema3 = close > ema3
// Bullish Engulfing Conditions
bullishSignal = c3 and c2 and engulfed and c0_bull and close_above_c2high and c3_below_sma6 and c0_above_ema3
// Plotting text for bullish engulfing
plotshape(bullishSignal, title="Bullish Engulfing", location=location.belowbar, color=color.green, style=shape.labelup, text="BuE")
// Optional: Bearish Engulfing Detection
c3_bear = close[2] > open[2] // 3 days ago green
c2_bear = close[1] < open[1] // 2 days ago red
engulfed_bear = (high[1] > high[2]) and (low[1] < low[2])
c0_bear = close < open // current red
close_below_c2low = close < low[1]
c3_above_sma6 = close[2] > sma6[2]
c0_below_ema3 = close < ema3
bearishSignal = c3_bear and c2_bear and engulfed_bear and c0_bear and close_below_c2low and c3_above_sma6 and c0_below_ema3
plotshape(bearishSignal, title="Bearish Engulfing", location=location.abovebar, color=color.red, style=shape.labeldown, text="BeU")
// Plotting Moving Averages
plot(sma6, color=color.orange, title="SMA 6")
plot(ema3, color=color.blue, title="EMA 3")
```
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.