|
|
Yearly RoC
Last post 12-31-2005, 1:54 by Jose. 8 replies.
-
11-26-2005, 4:18 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
This MS indicator plots the Rate of Change (RoC) for each year, resetting to zero (% or $) at the beginning of each year.
It may be useful for comparing markedly different charts, using the default % change option.
If there is a demand for it, I'll consider coding a monthly version of the same.
Code:
MetaStock -> Tools -> Indicator Builder -> New ->
Copy and paste complete formula between "---8<---" lines.
==========
Yearly RoC
==========
---8<-----------------------------
{ Yearly Rate of Change (RoC) v2.0
©Copyright 2004~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 }
method:=Input("Method: [1]%percent, [2]$points",1,2,1);
yr:=Input("RoC for Year [1800~2200]",
1800,2200,2005);
yrNr:=Input("Year's RoC: [1]Selected, [2]All",
1,2,2);
plot:=Input("plot: [1]RoC, [2]New Year signals",1,2,1);
{ Start of year }
init:=Cum(1)=2;
nuYear:=Year()<>Ref(Year(),-1) OR init;
{ Data Array }
x:=C;
{ Year's % RoC change }
chPer:=(x/ValueWhen(1,nuYear,x)-1)*100;
{ Year's $ RoC change }
chPts:=x-ValueWhen(1,nuYear,x);
{ Select %/$ RoC method }
ch:=If(method=1,chPer,chPts);
{ Restrict RoC to selected year }
chYear:=If(Year()=yr,ch,0);
chYear:=ValueWhen(1,chYear<>0 OR init,chYear);
{ Select individual year's RoC or all years }
chPer:=If(yrNr=1,chYear,ch);
{ Plot in own window }
If(plot=1,chPer,nuYear)
---8<-----------------------------
jose '-)
MetaStockTools.com
|
|
-
11-27-2005, 8:47 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Related to the above, this indicator plots the (selected or all) year's High & Lows:
Code:
MetaStock -> Tools -> Indicator Builder -> New ->
Copy and paste complete formula between "---8<---" lines.
============
Year's Hi/Lo
============
---8<-----------------------------
{ Yearly High & Low v2.0
©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 }
yr:=Input("Year [1800~2200]",1800,2200,2004);
yrNr:=Input("Year: [1]Selected, [2]All",
1,2,2);
plot:=Input("[1]Year's Hi/Lo, [2]NewYear signals",1,2,1);
{ Start of year }
init:=Cum(1)=2;
nuYear:=Year()<>Ref(Year(),-1) OR init;
{ Highest/Lowest of year }
YearHi:=HighestSince(1,nuYear,H);
YearLo:=LowestSince(1,nuYear,L);
{ Restrict High to selected year }
xYrHi:=If(Year()=yr,YearHi,0);
xYrHi:=If(Year()>=yr,xYrHi,C);
xYrHi:=ValueWhen(1,xYrHi>0,xYrHi);
{ Restrict Low to selected year }
xYrLo:=If(Year()=yr,YearLo,0);
xYrLo:=If(Year()>=yr,xYrLo,C);
xYrLo:=ValueWhen(1,xYrLo>0,xYrLo);
{ Select: individual year's Hi/Lo or all years }
pYrHi:=If(yrNr=1,xYrHi,YearHi);
pYrLo:=If(yrNr=1,xYrLo,YearLo);
{ Plot on price chart }
If(plot=1,pYrHi,0);
If(plot=1,pYrLo,nuYear)
---8<-----------------------------
jose '-)
MetaStockTools.com
|
|
-
-
11-28-2005, 23:42 |
-
-
12-23-2005, 19:12 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Yearly Rate of Change (RoC) v3.0
This indicator code update deals with the difficult issue of finding the correct closing price of the year.
Code:
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<-----------------------------
jose '-)
MetaStockTools.com
|
|
-
12-23-2005, 22:49 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Yearly Rate of Change (RoC) v4.0
This updated indicator now includes historical as well as yearly RoC plots.
Code:
==========
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 '-)
MetaStockTools.com
|
|
-
12-25-2005, 7:36 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Yearly Rate of Change (RoC) v4.1
This version now also plots RoC on the first incomplete year of data.
Code:
==========
Yearly RoC
==========
---8<-----------------------------
{ Yearly Rate of Change (RoC) v4.1
Note:
First incomplete year plots RoC from 4th bar.
©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 OR Cum(1)=4),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 '-)
MetaStockTools.com
|
|
-
12-31-2005, 1:54 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
How well did your market perform in 2005?
Code:
RoC % for year 2005
-------------------
Indices
-------
+40.2% Nikkei 225
+27.1% DAX
+23.4% CAC 40
+17.6% ASX 200
+16.7% FTSE 100
+7.0% NYSE Composite
+4.5% Hang Seng
+3.0% S&P 500
+1.4% Nasdaq Composite
-0.5% Dow Jones
Commodities
-----------
+40.5% Crude Oil
+15.1% Wheat (Kansas)
+13.8% Gold
Currencies/USD$
---------------
+3.5% Canadian $
-6.0% Australian $
-10.1% British Pound
-12.5% Euro
-12.7% Japanese Yen
jose '-)
MetaStockTools.com
|
|
|
|