Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
Asish, Here is my take on the code.... see what you think. I think I have covered all the bases amd got it right. I haven't done any extensive testing. It works on daily plots only. It will get all screwed up if you try another periodicity! Code:
{CountDown to the last Thursday in the Month}
{coded by wabbit :D}
{http://www.wabbit.com.au}
{26 September 2006}
{uses Jose Silvas Calendar code}
{http://www.metastocktools.com/MetaStock/DaysSince.txt}
{Event}
d:=4; {Thursday}
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;
m:=Month();
nm:=m+1;
nm:=If(nm>12,1,nm);
DaysinThisMonth:=
If(m=1 OR m=3 OR m=5 OR m=7 OR m=8 OR m=10 OR m=12,31,
If(m=4 OR m=6 OR m=9 OR m=11,30,28+leap));
DaysinNextMonth:=
If(nm=1 OR nm=3 OR nm=5 OR nm=7 OR nm=8 OR nm=10 OR nm=12,31,
If(nm=4 OR nm=6 OR nm=9 OR nm=11,30,28+leap));
event:=DayOfWeek()=d AND (DaysinThisMonth-DayOfMonth())<7;
{Calendar counter engine}
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();
{Days since event}
DaysSince:=DayNr-ValueWhen(1,event,DayNr);
{countdown}
z:=If(35-ValueWhen(1,event,DaysinThisMonth-DayOfMonth())>ValueWhen(1,event,DaysinNextMonth),28,35);
cd1:=z-DaysSince;
{No Event this month!}
event:=cd1<=0 AND Alert(cd1>0,2);
DaysSince:=DayNr-ValueWhen(1,event,DayNr-cd1-1);
z:=If(35-ValueWhen(1,event,DaysinThisMonth-DayOfMonth())>ValueWhen(1,event,DaysinNextMonth),28,35);
cd2:=z-DaysSince;
{plot}
If(cd1>0,cd1,cd2)
wabbit [:D]
|