[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [EquisMetaStock Group] Re: Yearly % change



PureBytes Links

Trading Reference Links

Great job, Jose! A couple of points though:

1) Is it possible to set it up such that it will automatically give the YTD 
% chnage value based on the date of the last bar (be it in a chart or in an 
exploration)?

2) It doesn't work for IPOs whose 1st bar is in the current year :(. Is it 
possible to modify the code such that it calculate the YTD % Chg for IPOs 
based on the 1st bar's Close (which would be the closest approximation that 
I can think of)? To help you, I have this code for 6month % change that 
takes care of just such an eventuality:  [As if you need my help!]
------------------------------------
TtlBars:= LastValue(Cum(1));
FirstDay:= If(TtlBars >126, TtlBars -126, 1);
FirstC:= ValueWhen(1, Cum(1) =FirstDay, C);
Round(((C/FirstC)-1)*100);
------------------------------------

If you could somehow mix the 2 codes together, it will ve very satisfactory.

JD
=========================

From: "Jose Silva" <josesilva22@xxxxxxxxx>
Reply-To: equismetastock@xxxxxxxxxxxxxxx
To: equismetastock@xxxxxxxxxxxxxxx
Subject: [EquisMetaStock Group] Re: Yearly % change
Date: Fri, 23 Dec 2005 22:49:55 -0000


This updated indicator now includes historical as well as yearly RoC.


==========
Yearly RoC
==========
---8<-----------------------------

{ Yearly Rate of Change (RoC) v4.0

©Copyright 2004~2006 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 }
method:=Input("Method:  [1]%percent,  [2]$points",1,2,1);
yr:=Input("RoC for Year [1800~2200]",
  1800,2200,2004);
yrNr:=Input("Yearly RoC:  [1]Year,  [2]Yearly,  [3]Historical",1,3,2);
plot:=Input("plot:  [1]RoC,  [2]Year signals",
  1,2,1);

{ Start/End of year }
nuYear:=Year()<>Ref(Year(),-1) OR Cum(1)=2;
YearEnd:=PeakBars(1,
  -(nuYear OR Cum(IsDefined(nuYear))=1),1)=0;
init:=Cum(IsDefined(YearEnd))=1;

{ Data Array }
x:=C;

{ Yearly $ RoC change }
chPts:=x-ValueWhen(1,YearEnd,x);
chPts:=If(YearEnd=0,chPts,
  Ref(chPts,-1)+x-Ref(x,-1));

{ Yearly % RoC change }
chPer:=(x/ValueWhen(1,YearEnd,x)-1)*100;
chPer:=If(YearEnd=0,chPer,
  Ref(chPer,-1)+(x/Ref(x,-1)-1)*100);

{ Select %/$ RoC method }
ch:=If(method=1,chPer,chPts);

{ Restrict RoC to selected year }
chYear:=If(Year()=yr,ch,0);
chYear:=If(Year()=yr,chYear,
  ValueWhen(1,
   init OR YearEnd AND Year()=yr,chYear));

{ Historical RoC from beginning of chart }
chAllPts:=x-ValueWhen(1,Cum(1)=1,x);
chAllPer:=(x/ValueWhen(1,Cum(1)=1,x)-1)*100;

{ Select %/$ historical RoC method }
chAll:=If(method=1,chAllPer,chAllPts);

{ Select type of Yearly RoC }
YearRoc:=If(yrNr=1,chYear,If(yrNr=2,ch,chAll));

{ Plot in own window }
If(plot=1,YearRoc,nuYear-YearEnd)

---8<-----------------------------


jose '-)
http://www.metastocktools.com




--- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" <josesilva22@xxxx>
wrote:
 >
 > This indicator code update deals with the difficult issue of finding
 > the correct closing price of the year.
 >
 >
 > MetaStock -> Tools -> Indicator Builder -> New ->
 > Copy and paste complete formula between "---8<---" lines.
 >
 > ==========
 > Yearly RoC
 > ==========
 > ---8<-----------------------------
 >
 > { Yearly Rate of Change (RoC) v3.0
 >
 > ©Copyright 2004~2006 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 }
 > method:=Input("Method:  [1]%percent,  [2]$points",1,2,1);
 > yr:=Input("RoC for Year [1800~2200]",
 >  1800,2200,2004);
 > yrNr:=Input("Year's RoC:  [1]Selected,  [2]All",
 >  1,2,2);
 > plot:=Input("plot:  [1]RoC,  [2]Year signals",
 >  1,2,1);
 >
 > { Start/End of year }
 > nuYear:=Year()<>Ref(Year(),-1) OR Cum(1)=2;
 > YearEnd:=PeakBars(1,
 >  -(nuYear OR Cum(IsDefined(nuYear))=1),1)=0;
 > init:=Cum(IsDefined(YearEnd))=1;
 >
 > { Data Array }
 > x:=C;
 >
 > { Year's $ RoC change }
 > chPts:=x-ValueWhen(1,YearEnd,x);
 > chPts:=If(YearEnd=0,chPts,
 >  Ref(chPts,-1)+x-Ref(x,-1));
 >
 > { Year's % RoC change }
 > chPer:=(x/ValueWhen(1,YearEnd,x)-1)*100;
 > chPer:=If(YearEnd=0,chPer,
 >  Ref(chPer,-1)+(x/Ref(x,-1)-1)*100);
 >
 > { Select %/$ RoC method }
 > ch:=If(method=1,chPer,chPts);
 >
 > { Restrict RoC to selected year }
 > chYear:=If(Year()=yr,ch,0);
 > chYear:=If(Year()=yr,chYear,
 >  ValueWhen(1,
 >   init OR YearEnd AND Year()=yr,chYear));
 >
 > { Select individual year's RoC or all years }
 > chPer:=If(yrNr=1,chYear,ch);
 >
 > { Plot in own window }
 > If(plot=1,chPer,nuYear-YearEnd)
 >
 > ---8<-----------------------------
 >
 > All good things come to those that wait. ;)
 >
 >
 > jose '-)
 > http://www.metastocktools.com
 >
 >
 >
 > --- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" <josesilva22@xx
..> wrote:
 >
 > John, to determine the correct last trading day of year for dates
 > other than 31st Dec, would involve some hindsight code in MetaStock.
 >
 > This hindsight-based code is part of the solution for the current
 > MetaStock competition
 > ( http://www.metastocktools.com/comp/comp-01.htm ),
 > so I'll tackle this one after we have our second winner there.
 >
 >
 >> Also, if this were run in an exploration whose last date, for
 >> testing purposes, may be set to a prior year, will it still
 >> calculate the change based on the current year (currently 2005) or
 >> on the last date set in the exploration?
 >
 > If you set the referenced indicator's default to a specific year,
 > the exploration will return the yearly RoC% for only that specific
 > year.
 >
 >
 > jose '-)
 > http://www.metastocktools.com
 >
 >
 >
 >
 > --- In equismetastock@xxxxxxxxxxxxxxx, "John Doe" <ms001122@xxxx>
 > wrote:
 >
 > Jose,
 > Some time back you posted the formula for calculating this year's %
 > change:
 >
 > { User inputs }
 > yr:=Input("% change for Year [1800~2200]",
 >   1800,2200,2000);
 > yrNr:=Input("Year:  [1]Selected,  [2]All",
 >   1,2,1);
 > plot:=Input("plot:  [1]% Change,  [2]New Year markers",1,2,1);
 >
 > { Start of year }
 > init:=Cum(1)=2;
 > nuYear:=Year()<>Ref(Year(),-1) OR init;
 >
 > { Data Array }
 > x:=C;
 >
 > { Year's % change }
 > ch:=(x/ValueWhen(1,nuYear,x)-1)*100;
 > chYear:=If(Year()=yr,ch,0);
 > chYear:=ValueWhen(1,chYear<>0 OR init,chYear);
 >
 > { Select individual year's % or all }
 > chPer:=If(yrNr=1,chYear,ch);
 >
 > { Plot in own window }
 > If(plot=1,chPer,nuYear)
 > ------------------------------------------
 >
 > There's an error in this as it calculates change from the Close of
 > 1st trading day of this year, whereas by convention the yearly %
 > change is always calculated from the last close of previous trading
 > year. The error lies here:
 >
 > ch:=(x/ValueWhen(1,nuYear,x)-1)*100;
 >
 > as its using nuyear's value, not last year's. Can you fix this
 > please?
 >
 > Also, if this were run in an exploration whose last date, for
 > testing purposes, may be set to a prior year, will it still
 > calculate the change based on the current year (currently 2005) or
 > on the last date set in the exploration?










Yahoo! Groups Links







------------------------ 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/