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)
|
Hi Ztrader
Modifying my Date Filter provides a very flexible way of selecting any required date range, and with that part of the problem dealt with there are a number of ways to extract the highest CLOSE within that range. The last line of Column A provides one solution, and I'm sure there are several other ways to arrive at the same result. The CLSN result returned by this code is $1.87.
{Column A} {Date Filter for exploration} Sd:=31; {Start day} Sm:=5; {Start month} Sy:=2013; {Start year} Ed:=8; {End day} Em:=7; {End month} Ey:=2013; {End 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); Filter:=Start AND (End OR (Start AND Alert(Start=0,2))); ValueWhen(1,Filter,HighestSince(1,Filter=0,C));
An alternative final line is... Highest(Filter*C); ... but this syntax will not work if looking for any lowest value. That's because Highest() and Lowest() functions include values outside the filter range - if the Filter was FALSE then Lowest(Filter*C) would return 0 (CLOSE multiplied by zero).
I suggest that you use a copy of the Date Filter indicator and experiment with last-line vaiations. Dropping an indicator onto a chart to see what the code is doing is a much easier way to troubleshoot your efforts than trying to figure out what's going on in an exploration. An indicator instantly shows you whether it's working correctly. Unfortunately you can't get that sort of feedback from code in an exploration, not without a lot more effort and guesswork anyway.
Oh, and here's Date Filter indicator code.
{Date Filter} {Roy Larsen, 2003-2010} Sd:=Input("Start day" ,1,31,1); Sm:=Input("Start month",1,12,1); Sy:=Input("Start year" ,1980,2020,2012); 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); Filter:=Start AND (End OR (Start AND Alert(Start=0,2))); Filter;
Roy
|