PureBytes Links
Trading Reference Links
|
Ever wanted a BarsSince() function that counts calendar days (instead
of data bars) from the last Nth event (not just the last one)?
This DaysSince indicator is similar to the BarsSince() function: it
plots calendar day count since the last Nth event occurrence, and the
calendar day count is independent of any chart periodicity or missing
data.
MetaStock -> Tools -> Indicator Builder -> New ->
Copy and paste complete formula between "---8<---" lines.
=========
DaysSince
=========
---8<--------------------------
{ DaysSince last Nth event function }
{ Calendar day count is independent of
any chart periodicity or missing data.}
{ ©Copyright 2003~2005 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 }
nth:=Input("Calendar days since Nth [1~1000] event",1,1000,1);
plot:=Input("[1]DaysSince, [2]EventSignals, [3]DayCount",1,3,1);
limit:=Input("Zero reset calendar days from year",1,2100,2000);
{ Event example }
event:=Cross(Mov(C,5,E),Mov(C,20,E));
{ Gregorian calendar }
LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0
OR Frac(limit/400)=0;
NoCount:=limit*365+Int(limit/4)
-Int(limit/100)+Int(limit/400)-LimLeap;
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)-NoCount;
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();
{ Restrict Nth to max events }
nth:=
LastValue(If(nth>Cum(event),Cum(event),nth));
{ Days since Nth event }
DaysSince:=DayNr-ValueWhen(nth,event,DayNr);
{ Plot in own window }
If(plot=1,DaysSince,If(plot=2,event,DayNr))
---8<--------------------------
jose '-)
http://www.metastocktools.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/BefplB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/equismetastock/
<*> To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|