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

Notification

Icon
Error

Options
Go to last post Go to first unread
rasj  
#1 Posted : 9 years ago
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times

Hi,

I'm building an exploration based on daily data and as a part of that exploration I would like to compare today's development to last week and last month.

For example I would like to identify those stocks which has a down day which follows a down week which follows a down month. The down week wasn't a problem but can any body help med with the down month based on daily data?

 

Thanks,

mstt  
#2 Posted : 9 years ago
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 rasj Can you clarify what you mean by "month"? Do you mean calender months, a 22 bar section of daily data that ended 22 bars ago, or exactly what? I also have the same questions about "weeks" - is it actual weeks or 5-day trading periods? Roy
rasj  
#3 Posted : 9 years ago
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
Hi Roy, I mean last calender month. My solution for week changes: WeekOpen:= If(DayOfWeek() = 1, Ref(O,-5), If(DayOfWeek() = 2, Ref(O,-6), If(DayOfWeek() = 3, Ref(O,-7), If(DayOfWeek() = 4, Ref(O,-8), Ref(O,-9))))); WeekClose:= If(DayOfWeek() = 1, Ref(C,-1), If(DayOfWeek() = 2, Ref(C,-2), If(DayOfWeek() = 3, Ref(C,-3), If(DayOfWeek() = 4, Ref(C,-4), Ref(C,-5))))); {This is the correct formula writeif(WeekClose - WeekOpen > 0,"UP","DOWN") But writeif() doesn't work...} If(WeekClose - WeekOpen > 0,1,0) Thanks,
mstt  
#4 Posted : 9 years ago
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 rasj The WriteIf() and WriteVal() functions can only be used with the Expert Advisor. One way to easily identify the beginning (or end) of weeks and months is to use the following snippets of code. {Start of week} D:=DayOfWeek(); D<Ref(D,-1); {Start of month} M:=Month(); M<>Ref(1,-1); OPEN prices can be obtained by using ValueWhen(). {Start of week OPEN} D:=DayOfWeek(); D:=D<Ref(D,-1); ValueWhen(1,D,O); {Start of month OPEN} M:=Month(); M:=M<>Ref(1,-1); ValueWhen(1,M,O); {End of week CLOSE} D:=DayOfWeek(); D:=D<Ref(D,-1); ValueWhen(1,D,Ref(C,-1)); {End of month CLOSE} M:=Month(); M:=M<>Ref(1,-1); ValueWhen(1,M,Ref(C,-1)); If you want to look back a further week or month you simply need to change ValueWhen(1,D,Ref(C,-1)) to ValueWhen(2,D,Ref(C,-1)) or whatever number of (weekly or monthly) time frames back are required. I'm sure you're aware that you need to get the timing right. The start of frame signals I've suggested occur one bar past the end of frame, so you need to use Ref() or ValueWhen() to identify any previous bars CLOSE. I prefer to use ValueWhen() rather than Ref() when looking back weeks or months - ValueWhen() allows you to pick up OPEN or CLOSE prices for higher time frames more easily than Ref(). Hope this helps. Roy
mstt  
#5 Posted : 9 years ago
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 rasj Here's another couple of code snippets that you might find helpful. The down-count method allows you to generate any fixed interval range of bars relating to the last bar, 21 bars per time-frame in this case. To mark off the same size time-frames from the first bar simply use Cum(1) to create an up-count. Looking at APPL in the US market it seems that 21 periods is more representative of the average number of bars in a month than 22. {Nominal End of Month} DownCount:=LastValue(Cum(1))-Cum(1); NominalEOM:=DownCount/21 = Int(DownCount/21); NominalEOM; {Nominal End of Month CLOSE} DownCount:=LastValue(Cum(1))-Cum(1); NominalEOM:=DownCount/21 = Int(DownCount/21); ValueWhen(1,NominalEOM,C); Roy
rasj  
#6 Posted : 9 years ago
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
Hi Roy, Thank you for your suggestion but there's a problem when using ValueWhen. The last part of the array does not "use" the first part. For example: ValueWhen(1,M,Ref(C,-1)) will return the yesterday's close disregard the variable M in the first part. And if I enter ValueWhen(2,M,Ref(C,-1)) it will return the day before close... Needless to say, I have the same problem with open. It would have been so easy but this isn't the first time I have encountered problems with ValueWhen so I hardly ever use it in my explorations. I wonder though if it's only in exploration the problem exists? rasj
mstt  
#7 Posted : 9 years ago
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 rasj I suspect that your problem is not ValueWhen() but that your explorations are set for "minimum records". Change your exploration Options setting from "Load Minimum Records" to say 100 records. This button is used for ALL explorations, though there is an Options button for individual explorations that sets the effective date and periodicity. ValueWhen() and a few other functions will return wrong or N/A (null) results when used with the Minimum Records setting. Any function using an Exponential Moving Average internally will appear to work correctly but the fact is that you need up to five times as much data loaded than the Periods parameter stipulates. In general the Explorer will load about 30% more data than the maximum Periods parameter setting. However, that's way too little to generate an accurate result. ADX and all of its derivatives use Wilders Smoothing (a form of EMA). as do a surprising number of MetaStock functions. . It's surprising just how many MetaStock functions use an EMA internally - somewhere north of 30% is my estimate, so don't skimp on the amount of data loaded. ValueWhen() is notorious in this respect, but if you load the same amount of data as you use for each chart you can't go too far wrong. I'd suggest that you also test your new exploration columns as indicators. With an indicator you can add an output line for each variable you construct and actually see how it performs, correctly or otherwise. An exploration gives you no visual feedback and it's much harder to identify problems in an exploration than in an indicator. BarsSince(), HighestSince(), LowestSince(), HighestSinceBars(), LowestSinceBars(), and in fact any function using an Nth parameter will need sufficient data loaded for it to function properly. Hope this helps. Roy
rasj  
#8 Posted : 9 years ago
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
Hi Roy,

I've tried 100, 500 & 1000 records and it still doesn't work. And how can it? Because when I look @ this statement

{End of month CLOSE}
M:=Month();
M:=M<>Ref(1,-1);
ValueWhen(1,M,Ref(C,-1));

you are asking ValueWhen to return "yesterdays" close when M is True. An if I changed it to ValueWhen(2,M,Ref(C,-1)) I will get the close from the day/bar before that - in other words it's the same as ref(c,-2).

Unfortunately ref() only works with constants...


Robin

Edited by user 9 years ago  | Reason: Not specified

rasj  
#9 Posted : 9 years ago
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
But if I tried this instead - vola! {Find close of previous month} M:= Month()<>Ref(Month(),-1) OR Cum(1)=2; ValueWhen(1,M,Ref(C,-1)) Do you like it? Robin
mstt  
#10 Posted : 9 years ago
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 Robin My mistake - a simple typo. Sorry. {Start of month OPEN} M:=Month(); M:=M<>Ref(1,-1); ValueWhen(1,M,O); It should have been... {Start of month OPEN} M:=Month(); M:=M<>Ref(M,-1); ValueWhen(1,M,O); ValueWhen() does function as Ref(), the exception being when looking into the future is required. Those situations, however, are few and far between. The one small down-side is that ValueWhen() requires a few more characters, but that's not often an issue. One advantage of ValueWhen() is that it's less prone to add to the N/A count, and another is that it doesn't limit the delay period to just a number of bars. If you need a variable Ref() function then use the later version of the Forum DLL. Among other places you can download this from... www.metastocktips.co.nz/Forum.dll Again I apologise for the typo. Roy
mstt  
#11 Posted : 9 years ago
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 Robin Just saw your post. Looks good, particularly the use of Cum(1) to generate an initial signal. :-) Roy
rasj  
#12 Posted : 9 years ago
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
Thank you, Roy And here's the previous mth.'s open: M:= Month()<>Ref(Month(),-1) OR Cum(1)=2; ValueWhen(2,M,O) And thanks for the forum.dll advise, it's probably a newer version than what I'm running on... Robin
mstt  
#13 Posted : 9 years ago
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 Robin The newer Forum DLL is 188 KB in size whereas the first version is a little smaller at 164 KB. There are less functions in the original version and the function names tend to be different. At least a couple of functions were discontinued in the later version, but several other functions were added. Roy
thanks 1 user thanked mstt for this useful post.
rasj on 7/28/2015(UTC)
Users browsing this topic
Guest (Hidden)
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.

information You have 1 unread message(s) in your Inbox.