HaParticipant
New
Hi,
I’m trying to scan that N number of consecutive candles are bullish and above 20EMA.
I used a forloop to scan and I’m not getting a correct result.
Can someone please tell me if you see a problem with my code? or is there other way to code it?
Thank you.
I can’t read your code now (you’d better always post also the code, unless it’s over hundreds of lines).
This is the code:
N = 5 //5 consecutive candles
Ema20 = close > average[20,0](close)
Bullish = close > open
Cond = Ema20 AND Bullish
x = (summation[N](Cond) = N)
x is true whenever N consecutive bullish candles above ema20 are met.
HaParticipant
New
Hi
Thank you for the help.
I’d already tried the summation fonction before, it doesn’t work well.
That’s why I tried a forloop.
Here’s my entire code.
// N number of candles close above 20EMA and are bullish green
// Uptrend
ema20 = ExponentialAverage[20](close)
ema50 = ExponentialAverage[50](close)
ema200 = ExponentialAverage[200](close)
m1 = ema20 > ema50 and ema50 > ema200
m2 = ema20 > ema20[1]
// Bullish candles above 20EMA
NofBar = 5
rsltClose = 0
rsltCandle = 0
for i = 0 to NofBar do
rsltClose = close[i] > ema20
rsltCandle = close[i] > open[i]
next
// Volume & Price
vol = ExponentialAverage[60](Volume)
t1 = vol > 500000
t2 = close > 3 and close < 40
SCREENER[m1 and m2 and rsltClose and rsltCandle and t1 and t2]
My fault, I coded an SMA instead of EMA. Replace line 2 with:
Ema20 = close > average[20,1](close) //0=Sma, 1=Ema, 2=Wma, etc...
HaParticipant
New
Hi Roberto
Your code works, thank you.
Would you mind explain how the last line works ?
Can’t get my head around how you can give a condition in a price constant () then an arithmetic sum of that condition can bring back what I want.
It sums up the condition for the last N bars and the result must be N, otherwise it would mean that the condition is not true for all N bars.