Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Normal
0
false
false
false
MicrosoftInternetExplorer4
Hi Clemens
The code shown below is a mix of my Date Filter indicator and PP's solution to
the original question in this thread. The indicator code is shown first. What
this does is plot the percentage gain or loss starting from the Start date
through to the end data, and it then holds the end date value through to the
last bar of the current chart.
Exploration code follows the indicator. The number of bars loaded should be
sufficient to generate a result from all securities with sufficient data. Any
securities with insufficient data will report an N/A, but in any case the bar
count in Column B will tell you the number of bars available for those
securities. Column A will return the same result as the indicator unless
insufficient bars are loaded.
I hope this is satisfactory.
Roy
Code:
{Indicator}
{Date Range Percentage Gain/Loss}
Sd:=Input("Start day" ,1,31,1);
Sm:=Input("Start
month",1,12,1);
Sy:=Input("Start year"
,1980,2015,2011);
Ed:=Input("End day" ,1,31,31);
Em:=Input("End month" ,1,12,12);
Ey:=Input("End year" ,1980,2020,2012);
Start:=(DayOfMonth()>=Sd AND
Month()=Sm AND Year()=Sy) OR
Year()>Sy OR
(Year()=Sy AND Month()>Sm);
End:=(DayOfMonth()<=Ed AND
Month()=Em AND Year()=Ey) OR
Year()<Ey OR
(Year()=Ey AND Month()<Em);
Range:=Start*(End OR
Start*Alert(Start=0,2));
Start:=Range*Alert(Range=0,2);
StartPrice:=ValueWhen(1,Start,C);
EndPrice:=ValueWhen(1,Range,C);
100*(EndPrice-StartPrice)/StartPrice;
{Exploration}
{Date Range Percentage Gain/Loss}
{Column
A: PcntGain}
Sd:=31; {Starting day}
Sm:=12; {Starting month}
Sy:=2009;{Starting year}
Ed:=30; {Ending day}
Em:=10; {Ending month}
Ey:=2011;{Ending year}
Start:=(DayOfMonth()>=Sd AND
Month()=Sm AND Year()=Sy) OR
Year()>Sy OR
(Year()=Sy AND Month()>Sm);
End:=(DayOfMonth()<=Ed AND
Month()=Em AND Year()=Ey) OR
Year()<Ey OR
(Year()=Ey AND Month()<Em);
Range:=Start*(End OR
Start*Alert(Start=0,2));
Start:=Range*Alert(Range=0,2);
StartPrice:=ValueWhen(1,Start,C);
EndPrice:=ValueWhen(1,Range,C);
100*(EndPrice-StartPrice)/StartPrice;
{Column
B: ScanBars}
Cum(1);
st1\:*{behavior:url(#ieooui) }
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
|