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

Re: Divergence Indicator



PureBytes Links

Trading Reference Links

Gary,

> Michael, the indicator you posted requires two functions,
> RB_CheckPeak and RB_CheckValley.  Do you have those?

see below.

> Any idea who wrote this?

nope. but it works pretty good. you can use different indicators as an
input.

> Gary

michael

Function: RB_CheckValley

{*****************************************************************}
Inputs:PkNmbr(NumericSimple),MaxOfset(NumericSimple),
           PrcDif(numericsimple);
Vars:Last(0),First(0),TstVal(0),NextVal(0),PrevVal(0);

{PkNmbr - Barnumber of peak in stochastic that you are checking against
MaxOfset - Number of bars away from this PkNmbr that is allowable and
                   still considered a valid match
PrcDif - Minimun number of points between highs or lows of bars in
             order to be greater or less than.

Will return the offset bar number (bars back from current bar) of the
       valley bar or will return a Zero if there is no matching valley}

First = Barnumber - Minlist(PkNmbr+MaxOfset,Barnumber-1);
Last  = Barnumber - Maxlist(PkNmbr-MaxOfset,2);
RB_CheckValley = 0;

if First<=maxbarsback and Last<=maxbarsback then
begin
     For Value1 = First to  Last
     begin
          TstVal = Low[value1];
          PrevVal = Low[Value1+1];
          NextVal = Low[Value1-1];

{
       {***Check For Equal Bars***}
          value2 = 2;
          while TstVal = PrevVal
          begin
                 PrevVal = Low[value1+value2];
                 value2 = value2+1;
          end;
          value2 = 2;
          while TstVal = NextVal and value1-value2>= 0
          begin
                NextVal = Low[value1-value2];
                value2=value2+1;
            end;
}

            if NextVal-TstVal>=PrcDif points and
                 PrevVal-TstVal>=PrcDif points then
                           RB_CheckValley = value1;
       end;
end;
{**************************************************************}

Function: RB_CheckPeak

{*************************************************************}
Inputs:PkNmbr(NumericSimple),MaxOfset(NumericSimple),
           PrcDif(numericsimple);
Vars:Last(0),First(0),TstVal(0),PrevVal(0),NextVal(0);

{PkNmbr - Barnumber of peak in stochastic that you are checking against
MaxOfset - Number of bars away from this PkNmbr that is allowable and
                   still considered a valid match
PrcDif - Minimun number of points between highs or lows of bars in
             order to be greater or less than.

Will return the offset bar number (bars back from current bar) of the
       peak bar or will return a Zero if there is no matching peak}

First = Barnumber - Minlist(PkNmbr+MaxOfset,Barnumber-1);
Last  = Barnumber - Maxlist(PkNmbr-MaxOfset,2);

RB_CheckPeak = 0;
if First<=maxbarsback and Last<=maxbarsback then
begin
     For Value1 = First to  Last
     begin
          TstVal = High[value1];
          PrevVal = High[Value1+1];
          NextVal = High[Value1-1];

{
       {***Check For Equal Bars***}
          value2 = 2;
          while TstVal = PrevVal
          begin
                 PrevVal = High[value1+value2];
                 value2 = value2+1;
          end;
          value2 = 2;
          while TstVal = NextVal and value1-value2>= 0
          begin
                 NextVal = High[value1-value2];
                 value2=value2+1;
          end;
}

          if TstVal-NextVal>=PrcDif points and
               TstVal-PrevVal>=PrcDif points  then
                           RB_CheckPeak =value1;
     end;
end;

{***********************************************************************
*}