{Calendar counter engine}
x:=Year()-(Month()<3);
leap:=Int(x/4)-Int(x/100)+Int(x/400);
mth:=Int((2+153*(Month()-3+12*(Month()<3)))/5);
dayNr:=DayOfMonth()+mth+x*365+leap-730425;
dayNr:=
{End of Week signals}
End:=PeakBars(1,DayOfWeek(),1)=0
{Week's Close}
Cl:=ValueWhen(1,End,C);
prevCl:=ValueWhen(2,End,C);
{RSI 1}
pds1:=If(Cum(1)<pds1,Cum(1),pds1);
x:=(Cl>prevCl)*(Cl-prevCl);
up:=PREV*If(End,1-1/pds1,1)+If(End,x/pds1,0);
x:=(Cl<prevCl)*(prevCl-Cl);
dw:=PREV*If(End,1-1/pds1,1)+If(End,x/pds1,0);
Rsi1:=100-100/Max(1+up/Max(dw,.00001),1);
Rsi1:=If(tFrame=1,RSI(C,LastValue(pds1)),
{RSI 2}
pds2:=If(Cum(1)<pds2,Cum(1),pds2);
x:=(Cl>prevCl)*(Cl-prevCl);
up:=PREV*If(End,1-1/pds2,1)+If(End,x/pds2,0);
x:=(Cl<prevCl)*(prevCl-Cl);
dw:=PREV*If(End,1-1/pds2,1)+If(End,x/pds2,0);
Rsi2:=100-100/Max(1+up/Max(dw,.00001),1);
Rsi2:=If(tFrame=1,RSI(C,LastValue(pds2)),
{RSI 3}
pds3:=If(Cum(1)<pds3,Cum(1),pds3);
x:=(Cl>prevCl)*(Cl-prevCl);
up:=PREV*If(End,1-1/pds3,1)+If(End,x/pds3,0);
x:=(Cl<prevCl)*(prevCl-Cl);
dw:=PREV*If(End,1-1/pds3,1)+If(End,x/pds3,0);
Rsi3:=100-100/Max(1+up/Max(dw,.00001),1);
Rsi3:=If(tFrame=1,RSI(C,LastValue(pds3)),
{SMA}
x:=Cum(End*Cl);
Sma:=If(tFrame=1,Mov(C,pds4,S),
{Close}
Cl:=If(tFrame=1,C,Cl);
{Signals}
entry:=Rsi1>Rsi2 AND Rsi2>Rsi3 AND Cl>Sma;
x:=Rsi1<Rsi2 AND Rsi2<Rsi3 AND Cl<Sma;
{Plot in own window}
If(plot=1,entry-x,If(plot=2,Rsi1,Sma));
If(plot=1,entry-x,If(plot=2,Rsi2,Sma));
If(plot=1,entry-x,If(plot=2,Rsi3,Sma));
---8<---------------------------------------