In the attached screenshot one can see the EMA5 crosses over the EMA10, EMA20 and the EMA50 within the last 5 days. So I wrote the code as follow:
//P1=5
MyEMA1 = ExponentialAverage[5](close)
MyEMA2 = ExponentialAverage[10](close)
MyEMA3 = ExponentialAverage[20](close)
MyEMA4 = ExponentialAverage[50](close)
Cross1 = MyEMA1 crosses over MyEMA2
Cross2 = MyEMA1 crosses over MyEMA3
Cross3 = MyEMA1 crosses over MyEMA4
cP11 = summation[P1](Cross1) > 0
cP12 = summation[P1](Cross2) > 0
cP13 = summation[P1](Cross3) > 0
cSummation1 = cP11 and cP12 and cP13
return cSummation1
But the RETURN is 0.
As I just return the cP11 or cP12 or cP13, it is 1.
Where is my problem?
The screener is:
P1=5
MyEMA1 = ExponentialAverage[5](close)
MyEMA2 = ExponentialAverage[10](close)
MyEMA3 = ExponentialAverage[20](close)
MyEMA4 = ExponentialAverage[50](close)
Cross1 = MyEMA1 crosses over MyEMA2
Cross2 = MyEMA1 crosses over MyEMA3
Cross3 = MyEMA1 crosses over MyEMA4
cP11 = summation[P1](Cross1) > 0
cP12 = summation[P1](Cross2) > 0
cP13 = summation[P1](Cross3) > 0
cSummation1 = cP11 and cP12 and cP13
SCREENER[cSummation1]
in any case both the indicator and the screener are working as expected.
Hi! I can’t see it in the attached image.
Your code is correct. The most likely problem is that all three crossovers are not occurring within the same 5-candle window at the same time.
I have used this code below to visually see the junctions and I have checked on some assets and it works.
If you give me details of the ticker, timeframe and date I can check it.
P1=5
MyEMA1 = ExponentialAverage[5](close)
MyEMA2 = ExponentialAverage[10](close)
MyEMA3 = ExponentialAverage[20](close)
MyEMA4 = ExponentialAverage[50](close)
Cross1 = MyEMA1 crosses over MyEMA2
Cross2 = MyEMA1 crosses over MyEMA3
Cross3 = MyEMA1 crosses over MyEMA4
cP11 = summation[P1](Cross1) > 0
cP12 = summation[P1](Cross2) > 0
cP13 = summation[P1](Cross3) > 0
cSummation1 = cP11 and cP12 and cP13
if cSummation1 then
backgroundcolor("green",30)
endif
return cP11, cP12*2, cP13*3, cSummation1*4 style(line,2)
Sorry, maybe I made some error anywhere in my code. I rewrote my code and it works now.
@Iván:
The ticker is the Alamos Gold (AGI). You can test it during the August 2025.