logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Jose  
#1 Posted : Tuesday, May 3, 2005 5:17:57 AM(UTC)
Jose

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)
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. [code:1:2fbfe8b70a] ========= 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<-------------------------- [/code:1:2fbfe8b70a] jose '-) http://www.metastocktools.com
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.