[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Divergence



PureBytes Links

Trading Reference Links

In addition to what follows, there is also
Bill Brower's commercial divergence detection utility, "DivergEngine,"
which comes in two flavors -- one for use with bounded indicators only,
and one that can be used with both bounded and unbounded indicators. 
See http://www.insideedgesystems.com/diverg.htm for more information.

Regards,
Monte

    ________________________________________________________________


 Subject: 
       PaintBar Divergence Detection Code [Fwd: Code-List V1 #302]
   Date: 
       Sat, 29 Jan 2000 01:43:27 -0800
  From: 
       "Monte C. Smith" <montecs@xxxxxxxx>
    To: 
       montecs@xxxxxxxx



 


 Subject: 
       Code-List V1 #302
   Date: 
       Sat, 29 Jan 2000 00:32:39 -0600
  From: 
       Code-List@xxxxxxxxxxxxx (Code-List)
    To: 
       <Code-List@xxxxxxxxxxxxx>



Code-List                      Sat, 29 Jan 2000          Volume 1 :
Number 302

In this issue:

        CL_Osc/Price divergence


----------------------------------------------------------------------

Date: Fri, 28 Jan 2000 10:40:01 EST
From: DStan34930@xxxxxxx
To: code-list@xxxxxxxxxxxxx
Subject: CL_Osc/Price divergence
Message-ID: <78.c44707.25c31251@xxxxxxx>

  Sometime last month there was a question put to the Omega-list
as to if it was possible to indicate divergence of price to a
fixed-midpoint
oscillator. I suggested an elementary method but some struggled
with the code.
  So I wrote two paintbars, one for top divergence(above the
oscillator's
midpoint) and one for the bottoms.

{
  Copy  and paste these into paintbar studies in your PowerEditor and 
verify them after pasting.
The instructions on how to use them is in comment brackets within the
code. You may want to print it out.

dave stanley

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

{ZZZZZZZZZZZZZ...FIRST ONE...ZZZZZZZZZZZZZZZ}

{
=====================================
PaintBar: DivTops

Code written by david b. stanley 1/26/2000

last update:1/26/2000

  This paintbar study takes an oscillator and records
the highest points oscillator and Price reach while oscillator is
above the midpoint.
  The highest points are compared to the previous highest points.
If diversion occurs, the bars are painted.
  Choose a color and the maxbarsback setting equal to that required
by your oscillator. The default is currently set to maxbarsback=55
and color=magenta.
=====================================
}

inputs:
osc(average(rsi(c,9),14)), 
  {...substitute with any oscillator FUNCTION
...i.e. osc(PGTrend_osc)
...make certain you set maxbarsback in your paintbar study
....to match that need by your oscillator...}
price(C),
  {...if you don't want the bars to paint at exactly the point where
divergence begins but instead want to wait until divergence has
reached a certain point, place values in the Pfactor and Ofactor
inputs. Pfactor is the amount of price divergence to wait for
and Ofactor is the amount of oscillator divergence to wait for.
...}
Midpoint(0),
{...set the midpoint to match the midpoint of your oscillator...}
OB(0),
{...WARNING...OB must be >= to midpoint!!!...}
{...if you do not want the bars to be painted until the oscillator
reaches a certain point i.e. +3 then change this input to that value
...}
Pfactor(0),
{...if you want to wait for the price difference between tops to exceed
a certain value, use that value here as an input...}
Ofactor(0);
{...if you want to wait for the oscillator difference between bottoms
to exceed a certain value, use that value here as an input...}

vars:
oscT1(0),oscT2(0),oscT3(0),
oscB1(0),oscB2(0),oscB3(0),
priceT1(0),priceT2(0),priceT3(0),
priceB1(0),priceB2(0),priceB3(0),
topdiv(0),botdiv(0);


{...create tops and bottoms...}

if osc crosses above midpoint then begin
  oscT3=oscT2;oscT2=oscT1;oscT1=osc;
  priceT3=priceT2;priceT2=priceT1;priceT1=price;
end;

if osc crosses below midpoint then begin
  oscB3=oscB2;oscB2=oscB1;oscB1=osc;
  priceB3=priceB2;priceB2=priceB1;priceB1=price;
end;

{...increase tops and bottoms...}

if osc>midpoint then begin
  if osc>oscT1 then oscT1=osc;
  if H>priceT1 then priceT1=H;
end;

if osc<midpoint then begin
  if osc<oscB1 then oscB1=osc;
  if L<priceB1 then priceB1=L;
end;

{============================
Now you have the last 3 tops and bottoms of both the oscillator
and price stored away (assuming the oscillator has crossed 0
a total of 6 times
============================
You can now use these tops and bottoms for divergence comparison.
You can also use them in conjunction with the highest() and lowest()
functions as described in your EL manual.
i.e.
if highest(osc,28)<oscT1 and highest(H,28)=priceT1 then begin
  {...perform something here...}
end;
This was just an example. We are not using it in this paintbar.
============================}

{...detect divergence between oscillator and price tops...}

if oscB3>0 then begin

  {...Top divergence...}

    if
    (oscT1<oscT2-ofactor and priceT1>=priceT2+pfactor)
    or
    (oscT1>oscT2+ofactor and priceT1<=priceT2-pfactor)
    then topdiv=1
    else topdiv=0;

  {...Bottom divergence...}

    if
    (oscB1>oscB2+ofactor and priceB1<=priceB2-pfactor)
    or
    (oscB1<oscB2-ofactor and priceB1>=priceB2+pfactor)
    then botdiv=1
    else botdiv=0;

end;

{...PLOT...}

if topdiv=1 and osc>OB then begin
  plot1(H,"TopdivH");
  plot2(L,"TopdivL");
end;


{ZZZZZZZZZZZZZZZZ...SECOND ONE...ZZZZZZZZZZZZZZZZZZ}

{
=====================================
PaintBar: DivBots

Code written by david b. stanley 1/26/2000

last update:1/26/2000

  This paintbar study takes an oscillator and records
the lowest points oscillator and Price reach while oscillator is
below the midpoint.
  The lowest points are compared to the previous lowest points.
If diversion occurs, the bars are painted.
  Choose a color and the maxbarsback setting equal to that required
by your oscillator. The default is currently set to maxbarsback=55
and color=cyan.
=====================================
}

inputs:
osc(average(rsi(c,9),14)), 
  {...substitute with any oscillator FUNCTION
...i.e. osc(PGTrend_osc)
...make certain you set maxbarsback in your paintbar study
....to match that need by your oscillator...}

price(C),
  {...if you don't want the bars to paint at exactly the point where
divergence begins but instead want to wait until divergence has
reached a certain point, place values in the Pfactor and Ofactor
inputs. Pfactor is the amount of price divergence to wait for
and Ofactor is the amount of oscillator divergence to wait for.
...}

Midpoint(0),
{...set the midpoint to match the midpoint of your oscillator...}

OS(0),
{...WARNING...OS must be <= to midpoint!!!...}
{...if you do not want the bars to be painted until the oscillator
reaches a certain point i.e. -3 then change this input to that value
...}

Pfactor(0),
{...if you want to wait for the price difference between bottoms to
exceed
a certain value, use that value here as an input...}

Ofactor(0);
{...if you want to wait for the oscillator difference between bottoms
to exceed a certain value, use that value here as an input...}

vars:
oscT1(0),oscT2(0),oscT3(0),
oscB1(0),oscB2(0),oscB3(0),
priceT1(0),priceT2(0),priceT3(0),
priceB1(0),priceB2(0),priceB3(0),
topdiv(0),botdiv(0);


{...create tops and bottoms...}

if osc crosses above midpoint then begin
  oscT3=oscT2;oscT2=oscT1;oscT1=osc;
  priceT3=priceT2;priceT2=priceT1;priceT1=price;
end;

if osc crosses below midpoint then begin
  oscB3=oscB2;oscB2=oscB1;oscB1=osc;
  priceB3=priceB2;priceB2=priceB1;priceB1=price;
end;

{...increase tops and bottoms...}

if osc>midpoint then begin
  if osc>oscT1 then oscT1=osc;
  if H>priceT1 then priceT1=H;
end;

if osc<midpoint then begin
  if osc<oscB1 then oscB1=osc;
  if L<priceB1 then priceB1=L;
end;

{============================
Now you have the last 3 tops and bottoms of both the oscillator
and price stored away (assuming the oscillator has crossed 0
a total of 6 times
============================
You can now use these tops and bottoms for divergence comparison.
You can also use them in conjunction with the highest() and lowest()
functions as described in your EL manual.
i.e.
if highest(osc,28)<oscT1 and highest(H,28)=priceT1 then begin
  {...perform something here...}
end;
This was just an example. We are not using it in this paintbar.
============================}

{...detect divergence between oscillator and price tops...}

if oscB3>0 then begin

  {...Top divergence...}

    if
    (oscT1<oscT2-ofactor and priceT1>=priceT2+pfactor)
    or
    (oscT1>oscT2+ofactor and priceT1<=priceT2-pfactor)
    then topdiv=1
    else topdiv=0;

  {...Bottom divergence...}

    if
    (oscB1>oscB2+ofactor and priceB1<=priceB2-pfactor)
    or
    (oscB1<oscB2-ofactor and priceB1>=priceB2+pfactor)
    then botdiv=1
    else botdiv=0;

end;

{...PLOT...}

if botdiv=1 and osc<OS then begin
  plot1(H,"BotdivH");
  plot2(L,"BotdivL");
end;

------------------------------

End of Code-List V1 #302
************************