Page 1 of 1

engulfing candle cross EMA

Posted: Fri Mar 31, 2023 4:28 pm
by Gr1sha
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

Re: engulfing candle cross EMA

Posted: Fri Mar 31, 2023 7:33 pm
by Gr1sha
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

Re: engulfing candle cross EMA

Posted: Sat Apr 01, 2023 2:05 am
by Steve Burman
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]

Re: engulfing candle cross EMA

Posted: Mon Apr 03, 2023 7:28 pm
by Gr1sha
Yes, it looks like I was making my life harder :-D Thank you