AlfyParticipant
Average
Hi guys, i have a code for distribution days below and i would like the code to calculate how many times in the last 20 trading days the condition is fulfilled. Can anyone help please?
thanks in advance
a=close
b=close[1]
c=volume
d=volume[1]
e=((a-b)/b)*100
j= high - low
IF e<-0.1 and C>D OR E<0.1 AND A<0.25*J AND C>D THEN
g=1
else
g=0
ENDIF
RETURN G COLOURED (255,0,0)
ONCE count=0
a=close
b=close[1]
c=volume
d=volume[1]
e=((a-b)/b)*100
j= high - low
IF e<-0.1 and C>D OR E<0.1 AND A<0.25*J AND C>D THEN
g=1
count=count+1
else
g=0
ENDIF
RETURN G COLOURED (255,0,0),count
counts each time G=1
Alfy – Please follow the forum rules in any future posts and use the ‘Insert PRT Code’ button whenever you put code in your posts. I edited your post to tidy it up! 🙂
AlfyParticipant
Average
First of all, thanks so much for your help. What I was trying to do was count how many times cumulatively G=1 in the last rolling 20 day period. Eyeballing it, currently we have had 3 occasions in the last 20 trading days when G=1 however your code shows only 1 occasion.
Best regards
You can make a summation of G for a rolling period with SUMMATION:
a=close
b=close[1]
c=volume
d=volume[1]
e=((a-b)/b)*100
j= high - low
IF e<-0.1 and C>D OR E<0.1 AND A<0.25*J AND C>D THEN
g=1
else
g=0
ENDIF
RETURN G COLOURED (255,0,0),summation[20](g)