Rank: Advanced Member
Groups: Registered, Registered Users Joined: 6/3/2005(UTC) Posts: 181
|
"Hi George,
This project was trickier to code than I thought, but I have tested it
on several charts and it plots perfectly. Please see attached pic.
I have added some useful extra options to the code - let me know what
you think.
And if you are happy with the code, please don't forget to mention it
in the forum. ;)
Regards,
jose
MetaStock -> Tools -> Indicator Builder -> New ->
Copy and paste all three complete formulae between "---8<---" lines.
Make sure all indicators are named correctly.
==========================
George-K - Original signal
==========================
---8<-----------------------------
{ Place original signal code below.
Example: }
Cross(Mov(C,63,S),Mov(C,252,S))
---8<-----------------------------
===============================
George-K - Calendar Day counter
===============================
---8<------------------------------------
{Gregorian calendar Week/Day counter v3.0.
Count is independent of any missing chart data.
©Copyright 2002~2006 Jose Silva.
The grant of this license is for personal use
only - no resale or repackaging allowed.
All code remains the property of Jose Silva.
http://www.metastocktools.com }
{ User inputs }
adj:=Input("Week's start: [0]Sunday, [1]Monday",0,1,1);
plot:=Input("Count: [1]Weeks, [2]Days",1,2,2);
{ Calendar counter engine }
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0
OR Frac(Year()/400)=0;
y:=Year()*365+Int(Year()/4)
-Int(Year()/100)+Int(Year()/400)-730484;
m:=
If(Month()=2,31-leap,
If(Month()=3,59,
If(Month()=4,90,
If(Month()=5,120,
If(Month()=6,151,
If(Month()=7,181,
If(Month()=8,212,
If(Month()=9,243,
If(Month()=10,273,
If(Month()=11,304,
If(Month()=12,334,
-leap)))))))))));
DayNr:=y+m+DayOfMonth();
adj:=adj+If(DayNr<1,1,2)
-(Frac(Year()/100)=0 AND Frac(Year()/400)<>0);
WkCount:=Int((DayNr-adj)/7)+(Year()>=2000);
{ Plot in own window }
If(plot=1,WkCount,DayNr)
---8<------------------------------------
=================================
George-K - Extended Binary signal
=================================
---8<-----------------------------------
{ Extends original binary signal by
Nth weeks or months.
Signal extension period is independent
of any missing chart data.
©Copyright 2006 Jose Silva.
The grant of this license is for personal use
only - no resale or repackaging allowed.
All code remains the property of Jose Silva.
http://www.metastocktools.com }
{ User inputs }
pds:=Input("Extend original signal by x periods",0,520,3);
type:=Input("Extension periods, use: [1]Weekly, [2]Monthly",1,2,2);
fill:=Input("Fill binary signal? [1]Yes, [0]No",0,1,1);
{ Reference signals }
signal:=Fml("George-K - Original signal");
{ Reference Calendar day/week counter }
day:=Fml("George-K - Calendar Day counter");
week:=FmlVar("George-K - Calendar Day counter","WKCOUNT");
{ Calendar month adjustment }
m:=Month();
nuMonth:=m<>Ref(m,-1) OR Cum(1)=2;
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0
OR Frac(Year()/400)=0;
adj:=If(m=5 OR m=7 OR m=10 OR m=12,1,
If(m=3,3-leap,0))*nuMonth;
adj:=Cum(adj)-ValueWhen(1,signal,Cum(adj));
mthPds:=pds*31-adj;
mthPds:=If(mthPds<1,1,mthPds);
{ Count Calendar periods since signal }
counter:=day-ValueWhen(1,signal,day);
wkCounter:=week-ValueWhen(1,signal,week);
{ Extended signal binary by x periods }
weekSignal:=wkCounter>=0 AND wkCounter<pds;
weekSignal:=If(signal AND weekSignal=0,
signal,weekSignal);
mthSignal:=counter>=0 AND counter<mthPds;
{ Select weekly or monthly extension }
extSignal:=If(type=1,weekSignal,mthSignal);
{ Eye candy }
even:=Frac(Cum(1)/2)=0;
odd:=Frac(Cum(1)/2)<>0;
{ Plot in own window }
If(fill*extSignal,even,0);
If(fill*extSignal,odd,0);
extSignal
---8<-----------------------------------
"
|