logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Ztrader  
#1 Posted : Tuesday, July 23, 2013 2:15:49 PM(UTC)
Ztrader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/12/2013(UTC)
Posts: 9

Hi,
This formula period is jun 2013 only. but i want to modify period to 31 may-8 july 2013. So i want to scan period 31 may-8 july 2013. can anyone help me ?

Highest(If(Month()=06 AND Year()=2013,C,0))
haddison  
#2 Posted : Wednesday, July 24, 2013 10:29:38 AM(UTC)
haddison

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/6/2010(UTC)
Posts: 113
Location: London

Use this for the date:

(
(Month()=5 and DayOfMonth()=31) or Month()=6 or (Month()=7 and DayOfMonth()<=8)
)
AND
Year()=2013
Ztrader  
#3 Posted : Wednesday, July 24, 2013 2:54:57 PM(UTC)
Ztrader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/12/2013(UTC)
Posts: 9

Dear Haddison,
Thank you so much. I try it. But result is wrong. Example; CLSN (Celsion-NASDAQ) highest close price is 1.87. But metastock scan result is 3.66 ! This is very interest. Can you help me this problem ?
mstt  
#4 Posted : Wednesday, July 24, 2013 5:40:42 PM(UTC)
mstt

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
Ztrader  
#5 Posted : Wednesday, July 24, 2013 6:20:28 PM(UTC)
Ztrader

Rank: Newbie

Groups: Registered, Registered Users
Joined: 7/12/2013(UTC)
Posts: 9

Dear Roy,
Thank you so much
haddison  
#6 Posted : Thursday, July 25, 2013 8:18:04 AM(UTC)
haddison

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/6/2010(UTC)
Posts: 113
Location: London

Roy is there anything wrong with my date formula?

Ztrader said the results are wrong but I tried it and it appears OK.

Thanks.
mstt  
#7 Posted : Thursday, July 25, 2013 2:43:50 PM(UTC)
mstt

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 haddison

I didn't test your formula yesterday, but I have now done so and found it to be spot on. My post was in no way intended to suggest there was a problem with your code and I apologise profusely if I gave that impression.

The sole reason I developed my indicator years ago was so I'd have a tool that allowed a quick and easy setup for any date range imaginable, and that's exactly what it does. In this instance I envisaged Ztrader possibly having a problem in getting at the highest price for the stipulated range. It's the sort of exercise that sometimes works fine on the first attempt, but more often that not turns out to be an exercise in frustration. With that in mind I added a couple of thoughts on how to complete the job.

Again I apologise for any offense given; certainly none was intended.

Roy




haddison  
#8 Posted : Friday, July 26, 2013 10:12:52 AM(UTC)
haddison

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/6/2010(UTC)
Posts: 113
Location: London

Thanks Roy, you're very polite! There was no need to apologise - I didn't take offense at all.

I've noticed that you don't use a number as the date. Is it because of rounding errors? I tried to make a formula for the date so that it would output a number with the date format as yyyyMMdd but because of Metastock's rounding errors I gave up and used a formula to output yMMdd (year 2000 onwards only) by deducting 2000 from Year(). For example this only results in even numbers:

Year()*10000+
Month()*100+DayOfMonth()

One is added to odd days of the month (except when DaysOfMonth()=1 where one is taken away).
mstt  
#9 Posted : Friday, July 26, 2013 3:43:56 PM(UTC)
mstt

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 haddison

You're spot on about the rounding errors, that's precisely my reason for not trying to combine day, month and year into one input value. I seem to recall that I've even had problems with splitting just month and year. From memory, even splitting a couple of 2-digit whole numbers can result in (tiny) errors.

What I usually do now, though only with quite small numbers, is force a bigger error (than MetaStock might cause) and then use the Int() function to eliminate the unwanted fractional remainder. Here's an example where 6 Input() functions are insufficient and I've been forced to combine the entry and exit delay periods in a Trade Equity indicator where D is split into D and Xd. Looking at the last line it would seem that only Xd uses the forced error anyway.

D:=Input("Entry/Exit Delays 00-55",0,55,00);
Xd:=LastValue(Int(Frac(D/9.9)*10));
D:=LastValue(Int(D/10));

LastValue() is used in this example to allow the results to be used as constants, so it's not part of the "fixing" process. This process only works when the required result has to deliver whole numbers. My advice would be to use all six Input() functions before trying to overcome the 6-input restriction, and then limit the number of digits to no more than 5. Don't expect 100% accuracy without taking additional precautions, and expect the unexpected when using Year() as an element of any project.

Roy


Users browsing this topic
Guest (Hidden)
Similar Topics
how to keep line study after change periodicity (MetaStock)
by newtrader123 6/27/2007 10:32:26 PM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.