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 : Wednesday, December 28, 2005 11:42:50 PM(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)
This indicator plots a trendline from a chosen date, based on a fixed % yearly growth rate - it may be useful as a benchmark reference. [code:1:7328aa5b73] ============================== Trendline - yearly % benchmark ============================== ---8<------------------------------------- { Trendline - yearly performance benchmark v2.2 Option "[1]Calendar days" will plot an uneven trendline on charts with missing data bars. ©Copyright 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 } StDay:=Input("start Day",1,31,1); StMnth:=Input("start Month",1,12,7); StYear:=Input("start Year",1800,2200,2005); growth:=Input("Yearly growth %",-1000,1000,20); plot:=Input("Trendline based on: [1]Calendar days, [2]Bars",1,2,1); { Date signal } active:=Year()>StYear OR (Year()=StYear AND (Month()>StMnth OR Month()=StMnth AND DayOfMonth()>=StDay)); date:=active AND Alert(active=0,2) OR Cum(1)=1; signal:=date AND Cum(date)=LastValue(Cum(date)); { Close at date signal } signalVal:=ValueWhen(1,signal,C); { Calendar day counter } limit:=2000; 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(); { Yearly growth % trendline } growth:=growth/If(plot=1,365,252)/100; counter:=If(plot=2,BarsSince(signal), DayNr-ValueWhen(1,signal,DayNr)); trend:=signalVal*(1+counter*growth); { Plot on price chart } trend ---8<------------------------------------- [/code:1:7328aa5b73] jose '-)
Jose  
#2 Posted : Thursday, December 29, 2005 8:05:20 PM(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)
This update now includes a real %pa performance option. [code:1:ebc843ef8c] ================================ Trendline - yearly %pa benchmark ================================ ---8<------------------------------------------ { Trendline - yearly performance benchmark v3.0 Option "[1]Calendar days" will plot an uneven trendline on charts with missing data bars. ©Copyright 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 } StDay:=Input("start Day",1,31,1); StMnth:=Input("start Month",1,12,7); StYear:=Input("start Year",1800,2200,2005); growth:=Input("Trendline Yearly Growth %pa", -1000,1000,20); type:=Input("Trendline based on: [1]Calendar days, [2]Bars",1,2,1); plot:=Input("[1]TrendLine, [2]Real %pa, [3]Tline-Real Diff",1,3,1); { Date signal } active:=Year()>StYear OR (Year()=StYear AND (Month()>StMnth OR Month()=StMnth AND DayOfMonth()>=StDay)); date:=active AND Alert(active=0,2) OR Cum(1)=1; signal:=date AND Cum(date)=LastValue(Cum(date)); { Close at date signal } signalVal:=ValueWhen(1,signal,C); { Calendar day counter } limit:=2000; 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(); { Yearly growth % trendline } growth:=growth/If(type=1,365,252); counter:=If(type=2,BarsSince(signal), DayNr-ValueWhen(1,signal,DayNr)); trend:=signalVal*(1+counter*growth/100); { Actual %pa performance } actual:=(C/signalVal-1)*36500 /Max(DayNr-ValueWhen(1,signal,DayNr),.000001); trend:=If(plot=1,trend,counter*growth); { Trendline on price chart, other in own window} If(plot=3,actual-trend,trend); If(plot=1,trend,If(plot=2,actual,actual-trend)) ---8<------------------------------------------ [/code:1:ebc843ef8c] jose '-)
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.