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

Notification

Icon
Error

Options
Go to last post Go to first unread
MS Support  
#1 Posted : Monday, July 28, 2014 1:34:06 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,934

Thanks: 85 times
Was thanked: 154 time(s) in 150 post(s)

Johnny Dough's article, “Reversing MACD: The Sequel” presented additional formulas for getting the price required for the MACD to give a signal on the next bar. The article include code for an all-in-one indicator. The indicator prompted for the MACD time periods and whether to use simple or exponential moving averages. It then plotted the close required on the next bar for three different signals; 1) the MACD to equal zero, 2) the MACD to equal the value on the current bar, and 3) the MACD to cross it's signal line. The MetaStock code for that indicator is listed below:

x:= Input("short term MA periods",1,50,12);

y:= Input("long term MA periods",2,50,26);

z:= Input("signal line periods",1,50,9);

type:= Input("MA type < 1=EMA | 2=SMA >",1,2,1);

ax:= 2/(x+1);

ay:= 2/(y+1);

az:= 2/(z+1);

cmacd:= Mov(C,x,E) - Mov(C,y,E);

smacd:= Mov(C,x,S) - Mov(C,y,S);

peflat:= (ax*Mov(C,x,E) - ay*Mov(C,y,E))/(ax-ay);

peeq0:= ((1-ay)*Mov(C,y,E) - (1-ax)*Mov(C,x,E))/(ax-ay);

pesig:= (Mov(cmacd,z,E) - (1-ax)*Mov(C,x,E) + (1-ay)*Mov(C,y,E))/(ax-ay);

psflat:= (x*Ref(C,-Y+1) - y*Ref(C,-x+1))/(x-y);

pseq0:= (x*y*(Mov(C,x,S)-Mov(C,y,S))+x*Ref(C,-y+1)-y*Ref(C,-x+1))/(x-y);

pssig:= ((x*y*z - x*y)*smacd - x*y*z*Mov(smacd,z,S) -

(y*z - y)*Ref(C,-x+1) + (x*z-x)*Ref(C,-y+1) +

x*y * Ref(smacd,-z+1) )/(x*z-y*z-x+y);

If(type=1,peflat,psflat);

If(type=1,peeq0,pseq0);

If(type=1,pesig,pssig);

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.