BullCharts Forum Homepage
Forum Home Forum Home > BullCharts > BullScript
  New Posts New Posts RSS Feed: Class A divergence
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Class A divergence

 Post Reply Post Reply Page  <12
Author
Message Reverse Sort Order
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post Posted: 25 Apr 2009 at 11:46pm
Hi Bana,
 
I had a good look at this indicator and have reconstructed the code for a few reasons.
 
1.  It didn't sync the indicator peaks with the price on the very bar the peak occurs.  This results in an occasional mismatch so
 indicating divergence when there wasn't any. This sync is also called correct correspondence.
 
2. Binary indicators aren't very user friendly.. like which spike means what again?
 
3. Also didn't show the actual indicator being used, which would be good to see.
 
 I have added the MACD difference (histogram line) and Stochastic Momentum.
You can now compare divergences on multiple indicators and see if they match.    
 
Enjoy!
 
 

[Description="Bullish & Bearish Divergence, Max"]

ind:=Input("MACD=1, RSI=2, DMI=3, STOC=4",4,1);

pds:=Input("indicator periods",5,1);

Ch:=Input("peak/trough depth minimum (0-100%)",0,0)/100;

MD := macd()-ma(macd(),9,E);

DS := ma((ma(C - llv(L,pds),pds,E) / ma(hhv(H,pds) - llv(L,pds),pds,E))*100,2,E);

y:=If(ind=1,MD,If(ind=2,RSI(C,pds),If(ind=3,DX(pds),DS)));

{ detect indicator peak }

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

{ save corresponding price bar of peak }

Pkx1:=ValueWhen(1,Pky,Ref(C,-1));

Pkx2:=ValueWhen(2,Pky,Ref(C,-1));

{ detect indicator trough }

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

{ save corresponding price bar of trough }

Trx1:=ValueWhen(1,Try,Ref(C,-1));

Trx2:=ValueWhen(2,Try,Ref(C,-1));

y;

[linestyle=marker; marker=type1; name=Bull_Div]

(Try AND Trx1<Trx2 AND Try1>Try2);

[linestyle=marker; marker=type2; name=Bear_Div]

(Pky AND Pkx1>Pkx2 AND Pky1<Pky2);



Edited by maximo - 26 Apr 2009 at 5:32pm
Back to Top
Bana View Drop Down
Regular
Regular
Avatar

Joined: 02 Jan 2007
Location: Australia
Posts: 46
Post Options Post Options   Quote Bana Quote  Post ReplyReply Direct Link To This Post Posted: 12 Apr 2009 at 4:50pm
thanks Maximo. Will give it a go and put feedback here later on.
Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post Posted: 12 Apr 2009 at 12:47am

 Gives interesting signals on XJO, have fun testing.

 

{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",2,1);

pds:=Input("indicator periods",10,1);

f:=Input("price field: Close=1, High/Low=2",1,1);

Ch:=Input("peak/trough depth minimum (0-100%)",0,0)/100;

shift:=Input("shift signals back to match divergences=1",0,0);

{ y:=insert any indicator or Fml("formula name") }

y:=If(ind=1,MACD(),If(ind=2,RSI(C,pds),If(ind=3,DX(pds),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)

Back to Top
Bana View Drop Down
Regular
Regular
Avatar

Joined: 02 Jan 2007
Location: Australia
Posts: 46
Post Options Post Options   Quote Bana Quote  Post ReplyReply Direct Link To This Post Posted: 11 Apr 2009 at 9:38am
Divergences are very powerful signals. Apparently there is a formula in Metastock to search for these. It would be worth testing if it can be converted to bullscript. Any help will be greatly appreciated. thanks


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)

Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz