# Type A Bullish Divergence Code



## lenny (21 December 2010)

Hi All, Wondering if someone has the code/script for Type A Bullish divergence on (RSI) for Metastock/Bull charts.

Has anyone done any testing with divergences?

Would appreciate any replies

Regards
Lenny


----------



## tech/a (21 December 2010)

lenny said:


> Hi All, Wondering if someone has the code/script for Type A Bullish divergence on (RSI) for Metastock/Bull charts.
> 
> Has anyone done any testing with divergences?
> 
> ...




Here is one from Jose.
{ Class A price/indicator divergence v3 }{ +1 signal = bullish trough divergences }{ -1 signal = bearish peak divergences }{  ©Copyright 2003 Jose Silva }{ josesilva22@yahoo.com }

ind:=Input("MACD=1,  RSI=2,  DMI=3,  Mom=4",1,4,1);
pds:=Input("indicator periods",2,2520,10);
f:=Input("price field: Close=1, High/Low=2",1,2,1);
Ch:=Input("peak/trough depth minimum (0-100%)",0,100,0)/100;
shift:=Input("shift signals back to match divergences=1",0,1,0);

{y:=insert any indicator or Fml("formula name")}
y:=If(ind=1,MACD(),If(ind=2,RSI(C,pds),
 If(ind=3,DMI(C),Mo(C,pds))));

xu:=If(f=1,C,H);
xd:=If(f=1,C,L);
Pkx:=xu<Ref(xu,-1) AND Ref(xu,-1)>Ref(xu,-2)
 AND Ref(xu,-1)>=(xu+Ref(xu,-2))/2*(1+Ch);
Pkx1:=ValueWhen(1,Pkx,Ref(xu,-1));
Pkx2:=ValueWhen(2,Pkx,Ref(xu,-1));
Trx:=xd>Ref(xd,-1) AND Ref(xd,-1)<Ref(xd,-2)
 AND Ref(xd,-1)<=(xd+Ref(xd,-2))/2*(1-Ch);
Trx1:=ValueWhen(1,Trx,Ref(xd,-1));
Trx2:=ValueWhen(2,Trx,Ref(xd,-1));

Pky:=y<Ref(y,-1) AND Ref(y,-1)>Ref(y,-2)
 AND Ref(y,-1)>=(y+Ref(y,-2))/2*(1+Ch);
Pky1:=ValueWhen(1,Pky,Ref(y,-1));
Pky2:=ValueWhen(2,Pky,Ref(y,-1));
Try:=y>Ref(y,-1) AND Ref(y,-1)<Ref(y,-2)
 AND Ref(y,-1)<=(y+Ref(y,-2))/2*(1-Ch);
Try1:=ValueWhen(1,Try,Ref(y,-1));
Try2:=ValueWhen(2,Try,Ref(y,-1));

0;
Ref(Trx AND Try AND Trx1<Trx2
 AND Try1>Try2,shift)
-Ref((Pkx AND Pky AND Pkx1>Pkx2
 AND Pky1<Pky2),shift)


----------



## lenny (22 December 2010)

Thanks Tech/a
will have a play around with it.

Lenny


----------



## tech/a (22 December 2010)

lenny.
Im not a real fan of Divergence in isolation but you may wish to have a look at this thread

https://www.aussiestockforums.com/forums/showthread.php?t=20202&page=2&highlight=Divergence

In the end 3 trades made good money but after the initial signal.


----------

