Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: Divergence indicator
Author/Uploader: M.Lauronen - pipseeker [at] yahoo.com
Date/Time added: 2004-07-30 11:50:32
Origin:
Keywords:
Level: medium
Flags: indicator

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

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.

Formula:

// ********************************************
// 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);

Comments:

Brian Elijah
cadvantag [at] goldengate.net
2004-08-01 01:17:21
Awesome Indicator! Thanks!

I changed one line to fit my needs.

trendMom = ROC(Close, 20 );
noname

2004-08-04 06:10:43
// 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[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, 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);
Lal

2004-08-04 17:42:12
Hi noname,

That is a very good indicator. Why not list it separately? Certainly deserves its own entry in the library.

Bob J.

2004-08-04 23:05:41
Hi noname,

Nice indicator! Can you re-create it for a black background? I tried but I am not that good at program language.

Thanks for a nice indicator!
noname

2004-08-05 17:54:17
2 Lal
This string make color RSI line.
Col = IIf(Div == 1, 4, IIf(Div == -1, 5, 1));

Col = IIf(Div == 1, 4 //color up divergence(Red)
, IIf(Div == -1, 5 //color down divergence(Green)
, 1 //default color(Black)
));
You can change color index.
Al
al_hobino [at] yahoo.com
2004-11-14 14:45:25
How can I convert this indicator into a scan or exploration? How can I add the buy and sell clauses (buy when green and sell when red)? Thanks.
spide
fergalator [at] yahoo.com
2005-08-19 14:22:42
How can I convert this indicator into a scan or exploration? How can I add the buy and sell clauses (buy when green and sell when red)? Thanks.
anon
fakemail [at] fakeserver.com
2005-09-04 11:06:09
Doesn't this look into the future by way of the Zig function? If that's the case how can it be used to trigger buy/sell signals?

Thanks.
Mithil
mithilpradhan [at] gmail.com
2010-02-06 05:48:01
Hi Noname,
Can we add yet another kind of divergence in this indicator? I am referring to the book \\\"Technical analysis for the trading professional\\\" by constance brown. If current RSI trough is at a new low while price is not, then its a bullish signal. Same way, if RSI make a new peak while price does not, then its a negative reversal. Thanks.
Raj
rajiv1 [at] gmail.com
2010-02-06 22:32:56
Hi Noname:

How can I convert this indicator into a scan or exploration and backtest it? Thanks.


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM