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

[amibroker] Updated code for divergences????



PureBytes Links

Trading Reference Links

Hi All,

Was wondering if anybody had any updated codes for the study of divergence
of an indicator? What I would like to do (but am unable due to limited AFL
programming) is to look at the difference of the actual divergence. First on
the indicator then the price. For example say an MACD had a .25 divergence
from the last two consecutive peaks. Or would a .35 be better? Thus would
like to explore the actual diff between peaks or valleys with plots then on
to a full system by comparing to price. Of course the MACD or RSI settings
would be a factor plus 1 tick to 1 day bars.

Below are two examples of code written awhile ago that could very well do
it, but am unable to decipher. 

Any help would be appreciated.



Jerry Gress
Stockton, Ca.


/* %R, ema 9 and divergences */
MaxGraph=5;
R=-100*((HHV(High,14)-Close))/(HHV(High,14)-LLV(Low,14));//14
DIVR=(R-Ref(R,-1))*(C-Ref(C,-1));
DIVB=IIf((DIVR<0) AND (R-Ref(R,-1))>0 AND (Ref(R,-1)<-90),-100,0);
DIVB1=IIf((DIVR<0) AND (R-Ref(R,-1))>0 AND (Ref(R,-1)<-90),-80,0);
DIVS=IIf((DIVR<0) AND (R-Ref(R,-1))<0 AND (Ref(R,-1)>-10),-20,0);
Graph2=DIVB1;
Graph2Style=2;
Graph2BarColor=0;
//Graph0 = R;
Graph0BarColor=12;
//Graph1=EMA(R,9);
Graph1BarColor=3;
Graph2=DIVB1;
Graph2Style=2;
Graph2BarColor=0;
Graph4=DIVB;
Graph4Style=2;
Graph3=DIVS;
Graph3Style=2;
Graph4BarColor=8;
Graph3BarColor=4;
Title=Name()+" - %R="+WriteVal(LastValue(R))+
WriteIf(DIVB==-100," POSITIVE DIVERGENCE"," ")+
WriteIf(DIVS==-20," NEGATIVE DIVERGENCE","");


// RSI divergence


P123 = Param("Priod RSI", 14, 9, 14, 1);
VRSI = RSI(P123);//rsi

Length = 100; 
Lapse = 3; 

fUp = VRSI > Ref(VRSI, -1) & VRSI > Ref(VRSI, 1) & VRSI >55;
fDown = VRSI < Ref(VRSI, -1) & VRSI < Ref(VRSI, 1) & VRSI < 45;

Div = 0;

for(i = Length; i < BarCount; i++)
{

// Down
if(fUp[i])
{
k = i-1;
do
{
if(VRSI[k] > VRSI[i] & fUp[i] & fUp[k])
{
if(C[k] < C[i] & i-k > Lapse)
{
Div[i] = 1;
}
k = i-Length;
}
else
k = k-1;
} while( k > i-Length );
}

////////////////////////////

// Up

if(fDown[i])
{
k = i-1;
do
{
if(VRSI[k] < VRSI[i] & fDown[i] & fDown[k])
{
if(C[k] > C[i] & i-k > Lapse)
{
Div[i] = -1;
}
k = i-Length;
}
else
k = k-1;
} while( k > i-Length );
}

}



Fon = IIf(Div == 0, 0, 1);

Col = IIf(Div == 1, 5, IIf(Div == -1, 6, 1));//1

Color = IIf(Div == 1, 4, IIf(Div == -1, 5, 1));//14
Color = IIf(fUp == 1, 4, IIf(fDown == 1, 5, 1));

Div = IIf(Div == 0, Null, abs(Div));
Fon = abs(Div);




Title = EncodeColor(4)+"RSI(" + WriteVal(P, 2.0) + ")" + EncodeColor(1) + "
="+WriteVal(RSI(P)); 
Plot( RSI(P), "RSI", Col, 5);
Plot( 25,"", 4, 16+4096);
Plot( 75,"", 4, 16+4096);
Plot(Fon, "", Color, 1638+32768+4096, MinValue = 0, MaxValue = 1);
Plot(Fon,"",colorRed,styleLine);
Plot(Fon, "", Color, 16384+32768+4096, MinValue = 0, MaxValue = 1);




------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a href="http://us.ard.yahoo.com/SIG=12h8no51s/M=362131.6882500.7825259.1493532/D=groups/S=1705632198:TM/Y=YAHOO/EXP=1123981481/A=2889190/R=0/SIG=10r90krvo/*http://www.thebeehive.org
">Put more honey in your pocket. (money matters made easy) Welcome to the Sweet Life - brought to you by One Economy</a>.</font>
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/