TF:=Input("1=hour 2=day 3=week 4=month 5=year ",1,5,4);
NW:=If(TF=1,ROC(Minute(),1,$)<0,If(TF=2,ROC(Hour(),1,$)<0,
If(TF=3,ROC(DayOfWeek(),1,$)<0,If(TF=4,ROC(DayOfMonth(),1,$)<0,ROC(Month(),1,$)<0))));
A1:=Cum(1);
A2:=LastValue(A1-BarsSince(NW>0));
WH:=ValueWhen(1,Nw,Ref(HighestSince(1,Nw,H),-1));
WL:=ValueWhen(1,Nw,Ref(LowestSince(1,Nw,L),-1));
WCL:=ValueWhen(1,Nw,Ref(C,-1));
BP:=LastValue((WH+WL+WCL)/3);
R#3:= If(A1<A2,BarsSince(A1>=A2),LastValue
(WH+(2*((WH+WL+WCL)/3) – WL)));
R#2:= If(A1<A2,BarsSince(A1>=A2),LastValue(((WH+WL+WCL)/3) -
(2*((WH+WL+WCL)/3)-WH) +(2*((WH+WL+WCL)/3)-WL)));
R#1:=
If(A1<A2,BarsSince(A1>=A2),LastValue(2*((WH+WL+WCL)/3)-WL));
PP:=If(A1<A2,BarsSince(A1>=A2),LastValue((WH+WL+WCL)/3));
S#1:=
If(A1<A2,BarsSince(A1>=A2),LastValue(2*((WH+WL+WCL)/3)-WH));
S#2:=
If(A1<A2,BarsSince(A1>=A2),LastValue(((WH+WL+WCL)/3)-(((2*((WH+WL+WCL)/3)
- WL)-(2*((WH+WL+WCL)/3)-WH)))));
S#3:=
If(A1<A2,BarsSince(A1>=A2),LastValue(WL-(2*(WH-(WH+WL+WCL)/3)));
R#3;
R#2;
R#1;
PP;
S#1;
S#2;
S#3;