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

Notification

Icon
Error

Options
Go to last post Go to first unread
EARTHCA  
#1 Posted : Saturday, December 19, 2009 7:10:16 PM(UTC)
EARTHCA

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/19/2009(UTC)
Posts: 4

I am using below formular to calculate peak line. The rule is peak line = High if High price is higher than previous High and higher than the high of subsequent 3 bars.

ValueWhen(1,H>Ref(H,-1) AND Ref(HHV(H,3),3)<H,H);

I tried to enhance the formular a bit. The rule is same as above rule, with excpetion that when high is lower than peak line formed previsouly, peak line = High if High price is higher than previous High and higher than the high of subsequent 2 bars.

I tried to use the combination of ValueWhen and PREV but it does not work.

Our expert please help to advice the possbile solution.

johnl  
#2 Posted : Saturday, December 19, 2009 9:31:02 PM(UTC)
johnl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 602

I get the same results when I use 3 periods or 2 periods. Maybe show on a chart
what you have in mind?


oztrader  
#3 Posted : Saturday, December 19, 2009 10:03:29 PM(UTC)
oztrader

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 7/12/2007(UTC)
Posts: 134
Location: Perth Western Australia

This looks somewhat familiar to the Bill Williams Fractal High from which the below formula has been adapted.

Use caution as this formula uses forward references (i.e. read the MetaStock Manual re forward references).

{Peak Line}

H1 := Ref(H,-1);
H2 := Ref(H,0);
H3 := Ref(H,1);
H4 := Ref(H,2);
H5 := Ref(H,3);

PeakTest:=
(H2>H1) AND (H2>H3) AND (H2>H4) AND (H2>H5);

PeakValue:=ValueWhen(1,PeakTest=1,H);

LastValue(PeakValue)

EARTHCA  
#4 Posted : Monday, December 21, 2009 8:04:17 AM(UTC)
EARTHCA

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/19/2009(UTC)
Posts: 4

Thanks both, i drawed one simple chart to illustrate what i need. Sorry i dont know how to attach chart i created one hyper link http://docs.google.com/View?id=dnssrk7_0724vphcc

B1 high is peak because it has 3 following lower bars. B1 would not be peak if it had only two following low bars.

A1 suppose not to be peak. It forms peak because it has 2 following bars AND it is lower than B1 peak line. (This is to form peak line with 2 following low bars if price drops)

B2 is not peak line because it has only 2 following low bar and its price is higher A1 (it would have formed peak link if it has 3 following lower bars)

Is it possbile it come out this indicator? I think the key is how to retrive previous K-Line be it 3-bars or 2 bars peak.

johnl  
#5 Posted : Monday, December 21, 2009 8:32:40 PM(UTC)
johnl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 602

The hyperlink helps. Thanks.
Play around with this:

a1:=ValueWhen(1,H>Ref(H,-1) AND Ref(HHV(H,3),3)<H,H);
a2:=ValueWhen(2,H>Ref(H,-1) AND Ref(HHV(H,3),3)<H,H);
a3:=If((a1>a2),a1,a2);
a3


EARTHCA  
#6 Posted : Monday, December 21, 2009 10:13:43 PM(UTC)
EARTHCA

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/19/2009(UTC)
Posts: 4

Hi Johnl,

this will not work as A1 will not form peak line as shown in the graph.

The key here is how to retrieve the return value of previous bar. Please note we can not compare with value ValueWhen(2,H>Ref(H,-1) AND Ref(HHV(H,3),3)<H,H) and ValueWhen(2,H>Ref(H,-1) AND Ref(HHV(H,2),2)<H,H). One of them could be 2nd last peak line that i am not going use.

I tried to use PREV, but it return the previous value of valuewhen funciton instead of that of itself.

Thank you!

oztrader  
#7 Posted : Tuesday, December 22, 2009 5:29:54 AM(UTC)
oztrader

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 7/12/2007(UTC)
Posts: 134
Location: Perth Western Australia

Hmmm......totally missed the mark with my last post.......must have been on a different wave length.

Hopefully this time my post may help with the problem to some extent.

{Peaks,Peaks & more Peaks}

H1:= Ref(H,-4);
H2:= Ref(H,-3);
H3:= Ref(H,-2);
H4:= Ref(H,-1);
H5:= Ref(H,0);
Test1:=
H2>H1 AND H2>H3 AND H2>H4 AND H2>H5;
Test2:=
H2>H1 AND H2>H3 AND H2>H4;
If(Test1,ValueWhen(1,Test1,H2),
If(Test2 AND BarsSince(Test1)>
BarsSince(Test2),ValueWhen(1,Test2,H2),PREV))

This indicator works from the last bar in the chart and, as such, the indicator represents a value that occurred at least two bars ago.

Cheers,

oz

EARTHCA  
#8 Posted : Wednesday, December 23, 2009 9:14:36 AM(UTC)
EARTHCA

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/19/2009(UTC)
Posts: 4

oz, thank you! yes it helps to some extend. i need your help to further explore.

I think hard how to make my requirement clearer. hope below is concise and easier to translate into computer language.

assume latest peak line is $X,

1) if H> (H-1) and H>(H-1) and > (H-2) and > (H-3), new peak link is H.

2)if H< $X and H> (H-1) and H>(H-1) and > (H-2) , new peak link is H.

please note latest peak line could be 2 bar peak line or 3 bar peak line, whichever newer.

For your posted solution, some times peak line is formed even with 2 bar even if it is higher than previous peak line, which could be 2 bar peak line.

The key thing is how to retrieve latest peak line. it comes to me that PREV can not be used.

after resolve, we still need to resolve the last 3 bars to populate peak line. I think it could be easier once we know how to retrieve lastest peak line.

oztrader  
#9 Posted : Wednesday, December 23, 2009 6:19:01 PM(UTC)
oztrader

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 7/12/2007(UTC)
Posts: 134
Location: Perth Western Australia

The amended code should suffice on the proviso that I have interpreted your explanation correctly.

{Peaks or Lower Peaks}

H1:= Ref(H,-4);
H2:= Ref(H,-3);
H3:= Ref(H,-2);
H4:= Ref(H,-1);
H5:= Ref(H,0);
Test1:=
H2>H1 AND H2>H3 AND H2>H4 AND H2>H5;
Test2:=
H2>H1 AND H2>H3 AND H2>H4;
V1:=ValueWhen(1,Test1,H2);
V2:=ValueWhen(1,Test2,H2);
If(Test1,V1,
If(Test2 AND
BarsSince(Test1)> BarsSince(Test2) AND
V1>V2,V2,PREV))

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.