Hi,
I want to count how many candles (before a bearish engulfing candle) that closes above the exponential moving average. I just cant figure out how to code it. I tried For-do-next and failed. can anyone help me with this?
There you go:
Bullish = close > open
Bearish = close < open
Opposite = (Bearish AND Bullish[1]) OR (Bearish[1] AND Bullish)
Body = abs(close - open)
Engulfing = (Body > Body[1]) AND Opposite
BearishEng= Engulfing AND Bearish AND (Open >= close[1]) AND (close <= open[1])
MyEma = average[50,1](close)
BarCount = 0
If BearishEng THEN
FOR i = BarIndex - 1 DOWNTO 1
x = BarIndex - i
IF close[x] > MyEma[x] THEN
BarCount = BarCount + 1
ELSE
BREAK
ENDIF
NEXT
ENDIF
RETURN BarCount