{ Downloaded From https://www.WiseStockTrader.com } { Trendline - yearly performance benchmark v3.3 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,1); StYear:=Input("start Year",1800,2200,2006); 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 counter engine } 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)-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(); { 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))