Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Try this indicator code:
[code:1:0eb8621f2d]
====================================
Highest/Lowest signals in retrospect
====================================
---8<----------------------------------------
{ Highest/Lowest signals/values in retrospect.
©Copyright 2006 Jose Silva.
For personal use only.
http://www.metastocktools.com }
{ User inputs }
pds:=Input("Lookback periods",1,21,2);
type:=Input("[1]Highest, [2]Lowest",1,2,1);
plot:=Input("Hi/Lo [1]Signals [2]Values, [3]Orig Up/Dw signals",1,3,1);
{ Original signals }
up:=Sum(H>Ref(H,-1),pds)=pds;
down:=Sum(L<Ref(L,-1),pds)=pds;
{ Clean signals }
init:=Cum(IsDefined(up+down))=1;
bin:=ValueWhen(1,up-down<>0 OR init,up);
up:=bin*(Alert(bin=0,2) OR up*Cum(up)=1);
down:=(bin=0)*(Alert(bin,2) OR down*Cum(down)=1);
{ Hi/Lo price between original clean signals }
a:=up+down;
b:=Mod(Cum(a),2)*2-1;
x:=Cum(1)>2;
HiSignal:=x*Abs(Zig(b*(H>=HighestSince(1,a,H)),2,$))=1;
HiVal:=ValueWhen(1,HiSignal,H);
LoSignal:=x*Abs(Zig(b*(L<=LowestSince(1,a,L)),2,$))=1;
LoVal:=ValueWhen(1,LoSignal,L);
{ Select Hi/Lo }
signal:=If(type=1,HiSignal,LoSignal);
value:=If(type=1,HiVal,LoVal);
{ Plot in own window }
If(plot=1,signal,If(plot=2,value,up-down))
---8<----------------------------------------
[/code:1:0eb8621f2d]
jose '-)
|