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);