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)
|
I'm just using plain old spliced continuous contract data for the data reference.
[code:1:86fbff2bb1] =============== US$ value index =============== ---8<------------------------------------------
{ US$ value index v5.0 Yearly Rate of Change - US$ vs Gold/Oil/Wheat.
Note: Gold/Oil/Wheat must be in US$. 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 }
{ Reference Gold/Oil/Wheat data } Gold:=Fml("URSC path Gold"); Oil:=Fml("URSC path Oil"); Wheat:=Fml("URSC path Wheat");
{ User inputs } plot:=Input("[1]Gold, [2]Oil, [3]Wheat, [4]Composite, [5]Year",1,5,4); yr:=Input("Yearly RoC: [1]Yearly, [2]Since [1800~2200]",1,2200,2002);
{ Start/End of year } init:=Cum(IsDefined(Gold+Oil+Wheat))=4 OR Cum(1)=4; nuYear:=Year()<>Ref(Year(),-1) OR init; first:=nuYear AND Year()=yr OR init; nuYear:=If(yr=1,nuYear,first); YearEnd:=PeakBars(1,-(nuYear OR Cum(IsDefined(nuYear))=1 OR init),1)=0;
{ RoC % Gold } x:=Gold; chPer:=(ValueWhen(1,YearEnd,x)/x-1)*100; chGold:=If(YearEnd=0,chPer, Ref(chPer,-1)+(Ref(x,-1)/x-1)*100);
{ RoC % Oil } x:=Oil; chPer:=(ValueWhen(1,YearEnd,x)/x-1)*100; chOil:=If(YearEnd=0,chPer, Ref(chPer,-1)+(Ref(x,-1)/x-1)*100);
{ RoC % Wheat } x:=Wheat; chPer:=(ValueWhen(1,YearEnd,x)/x-1)*100; chWheat:=If(YearEnd=0,chPer, Ref(chPer,-1)+(Ref(x,-1)/x-1)*100);
{ Composite Gold/Oil/Wheat RoC % } composite:=(chGold+chOil+chWheat)/3;
{ Select RoC output } Yroc:=If(plot=1,chGold, If(plot=2,chOil, If(plot=3,chWheat, composite))); Yroc:=Int(Yroc*100+If(Yroc>0,.5,-.5))/100;
{ Plot in own window } If(plot=5,nuYear-YearEnd,Yroc)
---8<------------------------------------------
[/code:1:86fbff2bb1]
jose '-)
|