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

Notification

Icon
Error

Options
Go to last post Go to first unread
Choychho  
#1 Posted : Sunday, September 23, 2012 4:41:00 AM(UTC)
Choychho

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 8/26/2010(UTC)
Posts: 6

Hi, I have created a custom indicator that show a peak has form. But the problem is I am not able to get get it to show it on the last trading bar. pk:=ValueWhen(1,(( HIGH>=Ref( HIGH , -1 ) ) AND (HIGH >= Ref(HIGH,+1))),H); pk; Please help. Thanks
henry1224  
#2 Posted : Sunday, September 23, 2012 8:00:58 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
You are using a forward Ref() function and will never get it to plot on the last bar,
Metastock is looking for the data into the future. since no data exists you will not get a signal.

Your code

Code:
 pk:=ValueWhen(1,(( HIGH>=Ref( HIGH , -1 ) ) AND 

(HIGH >= Ref(HIGH,+1))),H);



pk;



needs to referenced back

New code
Code:
 pk:=ValueWhen(1,(( Ref(H,-1)>=Ref( HIGH , -2 ) ) AND 

(Ref(H,-1) >= H)),Ref(H,-1));



pk;
Choychho  
#3 Posted : Sunday, September 23, 2012 9:51:05 AM(UTC)
Choychho

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 8/26/2010(UTC)
Posts: 6

Hi Henry, Thanks for your reply. My definition of peak: 1. Previous bar H has to be same or lower than Peak bar H 2. Next 3 consecutive bars has to be equal or lower than the H of the peak bar. My code is: pk:=ValueWhen(1,(( HIGH>=Ref( HIGH , -1 ) ) AND (HIGH >= Ref(HIGH,+1)) AND (HIGH >= Ref(HIGH,+2)) AND (HIGH >= Ref(HIGH,+3)),H); pk: But there will be no pk value on the last 3 bars. Hence no plot. Any advise on how to extend the pk value to the last 3 bars? Thanks in advance
henry1224  
#4 Posted : Monday, September 24, 2012 6:38:25 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
you are missing my point! Ref(HIGH,+3) is a forward Ref function, it makes metastock look forward for data, which has not occurred, hence no plot for the next three days!

to Plot on the last bar of a chart, the last bar is the current bar, all of the other bars are Ref(Bars,-lookback)

Please read the formula primer, do a search in the forum for it, go over the formulas with the user manual


Your code starts with a ref(Bar,-1) , the current bar, and the a forward Ref(bar,+1), you need to shift the bars 1 bar back to the left

Ref(bar,-2) , Ref(Bar,-1) ,and then the Current Bar
henry1224  
#5 Posted : Monday, September 24, 2012 12:46:44 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
here is a chart that should explain the theory behind this, look at the last bar on the chart

UserPostedImage

Code:
A:=If(H<Ref(H,-1) AND Ref(H,-1)>Ref(H,-2),2,
If(L>Ref(L,-1) AND Ref(L,-1)<Ref(L,-2),-2,0));
B:=If(Ref(H,1)<H AND H>Ref(H,-1),1,
If(Ref(L,1)>L AND L<Ref(L,-1),-1,0));
A;B;


Code A is a non forward Ref it is plotted in red and gives a signal on the last bar
Code B is a forward Ref, it is plotted in blue, it appears to give a signal 1 bar earlier than the red line, but if you look at the last bar it doesn't show up. That signal will not show up until tommorow. A day late and now a dollar short!

you can also see it work in MA's

UserPostedImage

Code:
A1:=Mov(C,10,S);
A2:=Mov(Ref(C,-1),10,S);
A3:=Mov(Ref(C,1),10,S);
A1;A2;A3;



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.