Hi,
Could you please check this screener and see whether I am close. It gave some results but I wanted confirmation that I coded the right thing?
Thanks.
CRITERIA
UP
- EMA 5 above EMA20, which is above EMA 50 and EMA100
- Bullish MACD crossover with MACD line crossing above the signal line
DOWN
- EMA 5 below EMA20, which is below EMA 50 and EMA100
- Bullish MACD crossover with MACD line crossing below the signal line
Ideally. I’ll want the bullish MACD crossover in the uptrend to happen below the zero line and the bearish MACD crossover to happen above the zero line.
Cheers.
Ema100 = Average [100,1] (close)
Ema50 = Average [50,1] (close)
Ema20 = Average [20,1] (close)
Ema5 = Average [5,1] (close)
MacdVal = Macd [12,26,9] (close)
UP = Ema5 > Ema20 AND Ema20 > Ema50 AND Ema50 > Ema100
DN = Ema5 < Ema20 AND Ema20 < Ema50 AND Ema50 < Ema100
Upa = summation [3] (MacdVal CROSSES OVER 0)
DNa = summation [3] (MacdVal CROSSES UNDER 0)
Result = 0
IF UP and UPa THEN
Result = 1
ELSIF DN and DNa THEN
Result = 2
ENDIF
SCREENER[Result] (Result AS "1=Up/2=Dn")
The CROSSES OVER 0 means that now it must be over 0 and the previous candle it was below 0, so it will always occur while below 0.
You added that the crossovers must have occurred in the last 3 candles, the current one or any of the two prior ones.
Yes, it’s all correct.