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 '-)
|