PureBytes Links
Trading Reference Links
|
This update now includes a real %pa performance option.
================================
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<------------------------------------------
jose '-)
http://www.metastocktools.com
--- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" <josesilva22@xxxx>
wrote:
>
> This indicator plots a trendline from a chosen date, based on a
> fixed % yearly growth rate - useful as a benchmark.
>
>
> MetaStock -> Tools -> Indicator Builder -> New ->
> Copy and paste complete formula between "---8<---" lines.
>
> ==============================
> 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<------------------------------
>
>
> jose '-)
> http://www.metastocktools.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Try Online Currency Trading with GFT. Free 50K Demo. Trade
24 Hours. Commission-Free.
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/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/
|