{Monthly Stochastic Oscillator EMA}
{2005 Roy Larsen,
www.metastocktips.co.nz}
{for use on daily charts}
N:=Input("Monthly Stochastic Oscillator Periods
(%K)",1,99,14);
K:=Input("%K Slowing Periods" ,1,99,1);
D:=Input("%D EMA
Periods",1,99,5);
Q:=Input("Display Mode, 0=Static
1=Dynamic 2=Test",0,2,1);
{0=Display, update at
end-of-month}
{1=Display, update on each new bar}
{2=Backtest, update on first bar of new
month}
G:=LastValue(Sum(Month()<>ValueWhen(2,1,Month()),5)=5);
M:=G
OR Month()<>ValueWhen(2,1,Month());
F:=G OR
PeakBars(1,Zig(If(G*(Cum(1)=1),1,DayOfMonth()),1,$),1)=0;
A:=LastValue(Cum(1)-1)=Cum(1);
B:=ValueWhen(2,1,A);
J:=If(F,1,If(Alert(F,2)=0
AND M,2,0));
J:=If(A+LastValue(J)>2 OR B+(Q=1)=2,1,J);
J:=If(G,1,If(Q=2
OR
Cum(J)<=1,M*2,J));
Hm:=HighestSince(1,M,H);
Hm:=ValueWhen(1,J,If(J=1,Hm,ValueWhen(2-G,1,Hm)));
Lm:=LowestSince(1,M,L);
Lm:=ValueWhen(1,J,If(J=1,Lm,ValueWhen(2-G,1,Lm)));
Cm:=ValueWhen(1,J,If(J=1,C,ValueWhen(2-G,1,C)));
Hm:=ValueWhen(1,Hm>0,Hm);
Lm:=ValueWhen(1,Lm>0,Lm);
Z:=Cum(LowestSince(N,M,Lm)*(J>0));
Z:=Cm-(Z-ValueWhen(K+1,J,Z));
I:=Cum((HighestSince(N,J,Hm)-LowestSince(N,J,Lm))*(J>0));
I:=I-ValueWhen(K+1,J,I);
I:=ValueWhen(1,Cum(I>0)>0,I);
X:=100*Z/I;
A:=2/(1+D);
X:=ValueWhen(1,Cum(J>0)>=K+N,X);
Y:=ValueWhen(1,J,PREV)*(1-A)+X*A;
Y:=ValueWhen(1,Cum(J>0)>=N+K+D,Y);
X;
{%K}
Y; {%D}