I want to develop a weekly screener with following conditions.
- EMA20 cross over EMA50 happened around six months back for the first time in the last two years
- Close is either very near to EMA[20] or moved below EMA20 only slightly
I developed the screener using lot of for loops and some calculations but getting very messy
I am just hoping to get some help in doing this relatively easy way please. Thanks in advance.
There you go (set TYPE=1 for EMAs, TYPE=0 for SMAs, etc…):
Timeframe(Weekly)
PerCent = 1 //1% above or below MA20 is to be considered VERY NEAR
Type = 1
MA20 = average[20,Type](close)
MA50 = average[50,Type](close)
c1 = (summation[104](MA20 CROSSES OVER MA50) = 1)
c2 = (summation[5](MA20[24] CROSSES OVER MA50[24]) = 1)
c3 = (close <= (MA20 * (1 + (PerCent / 100)))) AND (close >= (MA20 * (1 - (PerCent / 100))))
c4 = MA20 > MA50
Timeframe(default)
Cond = c1 AND c2 AND c3 AND c4 AND (high <> low)
SCREENER[Cond]
This worked like a magic and given me some good ideas on clean coding. Thank you very much.