divergences explore

#1
Pls help me to get ami formulars to explore divergences. I found in afl
library "divergences. afl" and tried it (it is very useful). As I
understand, This formular helps to find out (scan and explore) the
divergences between stochD and price. :confused:

However, I want a formular or formulars to find out the divergences
between RSI or CCI ... and price (by scan or explore)

Help me pls,

Thanks and regards,
 
#2
//------------------------------------------------------------------------------
//
// Formula Name: RSI Divergence
// Author/Uploader: Aron Pipa
// E-mail:
// Date/Time Added: 2006-03-19 22:00:02
// Origin:
// Keywords:
// Level: medium
// Flags: indicator
// Formula URL: http://www.amibroker.com/library/formula.php?id=603
// Details URL: http://www.amibroker.com/library/detail.php?id=603
//
//------------------------------------------------------------------------------
//
// + scanner
//
//------------------------------------------------------------------------------

/*---------------------------------------------------
RSI Divergence
Aron Pipa, March, 20 , 2006
--------------------------------------------------------*/

GraphXSpace=7;
n=Param("% Reverse ",20,0,100,1);

Buy=Sell=0;
Var = Zig(RSI(), n);
t= Trough(RSI(), n, 1);
p= Peak(RSI(), n, 1);
x[0] =Var[0];
price[0] = C[0];
j=0;

// bearish divergence
for ( i=0; i<BarCount; i++)
{
if(Var == p)
{

j++;
x[j] =Var;
price[j] =C;
if(x[j] <x[j-1] && price[j-1]< price[j])
Sell =1;
}
}

// bullish divergence
for ( i=0; i<BarCount; i++)
{
if(Var == t)
{
j++;
x[j] =Var;
price[j] =C;
if(x[j] >x[j-1] && price[j]<price[j-1])
Buy =1;
}
}

Plot(Var, "", 39);
PlotShapes ( IIf(Sell, shapeSmallCircle, shapeNone), colorRed, 0 , Var,0);
PlotShapes( IIf(Buy, shapeSmallCircle, shapeNone), colorBrightGreen, 0, Var,0);

Title ="RSI Divergence" ;
 
#3
// RSI divergence
// Backgraund color White


P = Param("Priod RSI", 14, 9, 14, 1);
VRSI = RSI(P);

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)
{
k = i-1;
do
{
if(VRSI[k] > VRSI & fUp & fUp[k])
{
if(C[k] < C & i-k > Lapse)
{
Div = 1;
}
k = i-Length;
}
else
k = k-1;
} while( k > i-Length );
}

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

// Up

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

}



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

Col = IIf(Div == 1, 4, IIf(Div == -1, 5, 1));

Color = IIf(Div == 1, 48, IIf(Div == -1, 14, 1));

Color = IIf(fUp == 1, 48, IIf(fDown == 1, 14, 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, 16384+32768+4096, MinValue = 0, MaxValue = 1);
 
#4
// N-bar momentum
function Mom( n )
{
return C - Ref( C, -n );
}
// N-bar fractional momentum
function fracMom( n )
{
return C / Ref( C, -n );
}
// S, L- bar fractional MACD
function fracMACD( s, L )
{
return EMA( C, s ) / EMA( C, L );
 
#5
//------------------------------------------------------------------------------
//
// Formula Name: Divergence indicator
// Author/Uploader: M.Lauronen
// E-mail: [email protected]
// Date/Time Added: 2004-07-30 11:50:32
// Origin:
// Keywords:
// Level: medium
// Flags: indicator
// Formula URL: http://www.amibroker.com/library/formula.php?id=374
// Details URL: http://www.amibroker.com/library/detail.php?id=374
//
//------------------------------------------------------------------------------
//
// Here is an indicator which calculates divergencies between the price and
// RSI.
//
// You can use another strenght/momentum indicator simple by changing one line
// of code.
//
// Remember to tune the 'period' and 'numChg'
//
// Indicator gives you the buy/sell signal when you see green/red vertical
// line on the panel.
//
//------------------------------------------------------------------------------

// ********************************************
// INDICATOR :DIVERGENCE
// DATE :07-30-04
// PROGRAMMER :M.Lauronen
// COPYRIGHTS :public Domain
// ********************************************

// --------------------------------------------
// Recommended AmiBroker indicator settings:
// Level 0
// Percent
// Middle
// Scaling: Custom 0 - 100
// --------------------------------------------

// Adjust the following parameters to suit your needs
period = 5;
numChg = 0.001;

// --------------------------------------------
// Divergence for LONG
// --------------------------------------------

trendMom = RSI(period);
trendZig = Zig(L, numChg);

f = trendZig > Ref(trendZig, -1) AND Ref(trendZig, -1) < Ref(trendZig, -2);

p1 = ValueWhen(f, Ref(trendZig, -1), 1);
p2 = ValueWhen(f, Ref(trendZig, -1), 2);
r1 = ValueWhen(f, Ref(trendMom,-1), 1);
r2 = ValueWhen(f, Ref(trendMom,-1), 2);

f = r1 > r2 AND p1 < p2;

sig = f AND NOT Ref(f, -1) AND trendMom > Ref(trendMom, -1);

_N(str = "(" + period + ")");
Plot(trendMom, "RSI" + str, colorWhite);
Plot(sig * 100, "Sig", colorGreen, styleHistogram + styleThick + styleNoLabel);

// --------------------------------------------
// Divergence for SHORT
// --------------------------------------------

trendZig2 = Zig(H, numChg);

f = trendZig2 < Ref(trendZig2, -1) AND Ref(trendZig2, -1) > Ref(trendZig2, -2);

p1 = ValueWhen(f, Ref(trendZig2, -1), 1);
p2 = ValueWhen(f, Ref(trendZig2, -1), 2);
r1 = ValueWhen(f, Ref(trendMom,-1), 1);
r2 = ValueWhen(f, Ref(trendMom,-1), 2);

f = r1 < r2 AND p1 > p2;

sig = f AND NOT Ref(f, -1) AND trendMom < Ref(trendMom, -1);

_N(str = "(" + period + ")");
Plot(sig * 100, "Sig", colorRed, styleHistogram + styleThick + styleNoLabel);
 
#6
Thanks Piyush Singh,

Could you pls add the scan and explore parts into these formulars so the users can easier find out the divergences.

;)