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 / View First Unread Post
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: 23 Dec 2009 at 10:53pm
Hi,
 
I'm not so sure that it would make it much faster, though give it a try and let me know.
 
 

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

d := InputDate("Start Date", date(2009,2,10));

start:=BarsSince(OnOrSkipped(d));

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

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

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

MD := if(start,macd()-ma(macd(),9,E), prev(undefined));

DSI := if(start,ma((ma(C - llv(L,pds),pds,E) / ma(hhv(H,pds) - llv(L,pds),pds,E))*100,2,E), prev(undefined));

y:=if(start,If(ind=1,MD,If(ind=2,RSI(C,pds),DSI)), prev(undefined));

{ 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 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 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 - 23 Dec 2009 at 11:02pm
Back to Top
hektorgsd View Drop Down
Newbie
Newbie


Joined: 21 Dec 2009
Posts: 2
Post Options Post Options   Quote hektorgsd Quote  Post ReplyReply Direct Link To This Post Posted: 24 Dec 2009 at 4:28pm

Hi Maximo,

 
That really makes it quicker. I really appreciate your helpClap
 
The new formula does not have DMI? Could you please help with the script with the DMI divergence with the start time option? I like having the four to compare!
 
Merry Xmas
 
H.
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: 25 Dec 2009 at 2:01am

Okay I've added DMI.  Good to hear it's faster.  

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

d := InputDate("Start Date", date(2009,2,10));

start:=BarsSince(OnOrSkipped(d));

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

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

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

MD := if(start,macd()-ma(macd(),9,E), prev(undefined));

DSI := if(start,ma((ma(C - llv(L,pds),pds,E) / ma(hhv(H,pds) - llv(L,pds),pds,E))*100,2,E), prev(undefined));

y:=if(start, If(ind=1,MD, If(ind=2,RSI(C,pds), If(ind=3,DSI, DX(pds)))), prev(undefined));

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

 
 
¸.·°¯°·.¸¸.-> Merry Christmas <-.¸¸.·°¯°·.¸   
Back to Top
sonu panwar View Drop Down
Newbie
Newbie
Avatar

Joined: 27 Feb 2010
Location: india
Posts: 5
Post Options Post Options   Quote sonu panwar Quote  Post ReplyReply Direct Link To This Post Posted: 27 Feb 2010 at 5:04pm

Let P and Q be two probability distributions over a space Ω such that P is absolutely continuous with respect to Q. Then, for a convex function f such that f(1) = 0, the f-divergence of Q from P is

%20D_f%28P%5Cparallel%20Q%29%20=%20%5Cint_%7b%5COmega%7d%20f%5Cleft%28%5Cfrac%7bdP%7d%7bdQ%7d%5Cright%29%5C,dQ.

If P and Q are both absolutely continuous with respect to a reference distribution μ on Ω then their probability densities p and q satisfy dP = p dμ and dQ = q dμ. In this case the f-divergence can be written as

%20D_f%28P%5Cparallel%20Q%29%20=%20%5Cint_%7b%5COmega%7d%20f%5Cleft%28%5Cfrac%7bp%28x%29%7d%7bq%28x%29%7d%5Cright%29q%28x%29%5C,d%5Cmu%28x%29.

Instances of f-divergences

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