Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/19/2005(UTC) Posts: 2,995
Was thanked: 14 time(s) in 10 post(s)
|
Thought I'd share this channel position indicator that I adapted from Jose's AutoEnvelopes. Comments welcome.
[code:1:c9d0b80e42]
{ _g4_ChannelPosition v1.0, g_stockman, 2006 }
{ Adapted from Jose Silva's AutoEnvelopes }
{ User inputs }
i1:=Input("EMA periods",1,252,10);
i2:=Input("Smoothing periods",0,10,1);
i3:=Input("Std Dev multiplier",0.01,10,1.5);
i4:=Input("Data Array (O=1 H=2 L=3 C=4 Typical=5)",1,5,5);
i4:=If(i3=1,O,If(i3=2,H,If(i3=3,L,If(i3=4,C,Typical()))));
i5:=Input("Plot (Channels=1 Signals=2)",1,2,1);
{ Constants }
c1:=2.7; { Standard deviation factor }
c2:=100; { Use 100 periods for stable channel size }
{ Channel size }
pavg:=Mov(i4,i1,E);
csize:=LastValue(Stdev(i3*Max(Abs(H-pavg),Abs(L-pavg))/pavg,c2)*c1);
{ Channels }
channel:=csize*pavg;
upper:=pavg+channel/2;
lower:=pavg-channel/2;
{ Channel position }
cpos:=Mov(100-((upper-C)/(upper-lower))*100,i2,E);
{ Signals }
up:=If(C>upper,1,0);
dn:=If(C<lower,-1,0);
{ Plot }
If(i5=1,cpos,0);
If(i5=1,50,0);
If(i5=1,100,0);
If(i5=2,up,0);
If(i5=2,dn,0);
0;
[/code:1:c9d0b80e42]
|