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

Notification

Icon
Error

Options
Go to last post Go to first unread
TimX  
#1 Posted : Thursday, October 25, 2012 9:33:08 PM(UTC)
TimX

Rank: Member

Groups: Registered, Registered Users
Joined: 10/26/2012(UTC)
Posts: 19

Hello, I'm a newcomer to Metastock and would appreciate it if anyone can give me a pointer on a problem I have. Basically I need to find the relative position of a cross. I have a (working) indicator of an event, but for each event I want to look back and see when the pattern started. Firstly, I look for an indicator that a higher high and a higher low than the past 3 periods has been reached, but this high has previously been bettered in the past 44 weeks (it is not an all-time new high): If((H > Ref(H,-1) AND H > Ref(H,-2) AND H > Ref(H,-3)) AND (L > Ref(L,-1) AND L > Ref(L,-2) AND L > Ref(L,-3)) AND (H < HHV(Ref(H,-4), 40)), 1, 0) That works fine: I get a series with 1 indicating this condition and 0 else. For a positive indication, I want to know how long previously (greater than 4 periods) the higher high and higher low was triggered. Any suggestions on how I can do this? If it was possible to loop, I would explicitly loop backwards until I hit the condition. I thought of using the Cross function, but that returns a series of 1s: I really need to relative position of the first 1. Once I have this relative position, I can define my 'box' of time and prices. Thank you, TimX
wabbit  
#2 Posted : Thursday, October 25, 2012 10:17:05 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
To start with, you don't need to do the If(something, 1,0) as MS will do this for you in its evaluation of the expression.

Next, I'd be writing your expression in a slightly different manner, because I think it makes the expression easier to read, and it's also faster to compute:

Code:

condition:=Sum(H>Ref(H,-1),3)=3 AND Sum(L>Ref(L,-1),3)=3);

{plot}
condition;


or even faster:
Code:

condition:=Sum(H>Ref(H,-1) AND L>Ref(L,-1),3)=3;

{plot}
condition;




To find the numbers of bars elapsed since the condition event, use BarsSince(). Work through the MS User Manual and the free Equis Formula Primer and you'll see how to use it.



wabbit [:D]

TimX  
#3 Posted : Sunday, October 28, 2012 9:26:47 PM(UTC)
TimX

Rank: Member

Groups: Registered, Registered Users
Joined: 10/26/2012(UTC)
Posts: 19

wabbit, thank you for your help, that's really useful. 'Ppreciated. TimX
TimX  
#4 Posted : Monday, October 29, 2012 12:05:33 AM(UTC)
TimX

Rank: Member

Groups: Registered, Registered Users
Joined: 10/26/2012(UTC)
Posts: 19

Hello again, I have a related question and I can't find any help in the Formula Primer or the MS Manual. I want to use the HHV and LLV functions, however the number of periods over which they work is a variable: MyLow := LLV(Data, NumPeriods); (Basically the lookback period to determine the reference point is not fixed.) MS formula language requires NumPeriods to be a scalar (single value) rather than an array / data series. However, NumPeriods is itself a variable, created as the output from previous calculations. If I was writing in a regular language, this wouldn't be a problem as I'd be able to pick out the Nth point from NumPeriods and put it into the LLV function. However I don't see how this can be done in Metastock. Does anyone have any suggestions? Thanks again, TimX
jjstein  
#5 Posted : Monday, October 29, 2012 12:14:16 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
"LastValue" should work:
Code:

MyLow := LLV(Data, LASTVALUE(NumPeriods)); 
TimX  
#6 Posted : Monday, October 29, 2012 12:21:04 AM(UTC)
TimX

Rank: Member

Groups: Registered, Registered Users
Joined: 10/26/2012(UTC)
Posts: 19

Hi Jonathan, My reading of LASTVALUE is that returns just the final point. I need the LLV to be calculated based on the value of NumPeriods at that point in time. E.g. if NumPeriods is [10, 12, 12, 15, 10, 15, 15, 4] and I'm looking for the LLV at the 4th timepoint, I want to calculate LLV(Data, 15), but if I'm looking at the 8th timepoint, I want to calculate LLV(data, 4). Thanks, TimX
wabbit  
#7 Posted : Monday, October 29, 2012 1:31:56 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
HighestSince(), LowestSince() might work for you, or, the variable lookback periods of the forum.dll HHV() and LLV() functions.


wabbit [:D]

TimX  
#8 Posted : Monday, October 29, 2012 2:15:21 AM(UTC)
TimX

Rank: Member

Groups: Registered, Registered Users
Joined: 10/26/2012(UTC)
Posts: 19

Thank you wabbit. It looks (from the manual) that forum.dll has exactly what I need. Unfortunately though I can't get MS to see the function. Here's my procedure: Closed MS. I went to http://forum.equis.com/drm_main.php (in the manual) but that's not there. So I went to the downloads section of this site and got this version: ForumDLL_200. (It's 188 kb.) Moved it to c:/Program Files/equis/Metastock/External Function Dlls/. Went to the properties and unblocked it. Started MS (version 11): Tools, Indicator Builder, New, Functions, But no 'Forum' on the left hand side... Do I have a good version? (I have MS 11 running on Windows 7.) Have I missed something in the installation procedure? Should I restart the PC? Thanks, TimX
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.