Gr1sha
Pine Script Scholar
Pine Script Scholar
Posts: 3
Joined: December 29th, 2022

engulfing candle cross EMA

Hello all,

I am new to pine script and am trying to create my first script.
Idea is to plot shape once bullEC or bearEC crosses over or under the EMA. Below you can see how I tried to do this, but it is plotting shape on every candle not just engulfing one.
If anyone can help me how to fix this, I would really appreciate it.

//Engaulfing candle

bullEC = open <= close[1] and close > open[1]
bearEC = open >= close[1] and close < open[1]


// Get ATR value
atr = ta.atr(14)

//Up and Down trend
uptrend = close > ema1 and ema1 > ema2
downtrend = close < ema1 and ema1 < ema2

//Buy and Sell conditions

buySignal = bullEC and uptrend
sellSignal = bearEC and downtrend

best regards

Gr1sha
Pine Script Scholar
Pine Script Scholar
Posts: 3
Joined: December 29th, 2022

Re: engulfing candle cross EMA

I gues a problem is how I define EC. This is what I changed and now I have less candles marked

//Engaulfing candle

bullEC = open <= close[1] and close > open and close > ema1
bearEC = open >= close[1] and close < open and close < ema1

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: engulfing candle cross EMA

This is Matt's take on engulfing candles and probably the definition to use for now.

bullEC = close[1] < open[1] and open <= close[1] and close >= open[1]
bearEC = close[1] > open[1] and open >= close[1] and close <= open[1]

Gr1sha
Pine Script Scholar
Pine Script Scholar
Posts: 3
Joined: December 29th, 2022

Re: engulfing candle cross EMA

Yes, it looks like I was making my life harder :-D Thank you

Return to “Pine Script Q&A”