How to trade divergence ? and where to put stops?

mohan.sic

Well-Known Member
Joined
Jul 2, 2009
Messages
3,293
Likes
5,453
#11
Dear Capricorn,

Can you provide me with an afl to scan divergence between price and rsi (14)
 

Capricorn

Well-Known Member
Joined
Aug 20, 2008
Messages
1,677
Likes
2,086
#12
I don't do AFL's but here's something from from a friend. I don't know if it works . Check it out.

// RSI Divergence - Plot and Explore

_SECTION_BEGIN("RSI divergence");

P = Param("Period 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, 32, IIf(Div == -1, 27, 1));

Color = IIf(fUp == 1, 32, IIf(fDown == 1, 27, 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 | styleOwnScale, MinValue = 0, MaxValue = 1);
_SECTION_END();

Filter=Fon==1;
AddColumn
(C,"Close",1.2,Color);

If you are willing to pay for it go here.

http://www.aflwriting.com/
 

mohan.sic

Well-Known Member
Joined
Jul 2, 2009
Messages
3,293
Likes
5,453
#14
Hi Capricorn,

Sorry for my previous post. I think its working. I plotted it as an indicator on chart window
and its showing Green Bar and Red Bar . But how to use this for scan purpose.
 

mohan.sic

Well-Known Member
Joined
Jul 2, 2009
Messages
3,293
Likes
5,453
#16
Dear capricorn,

Can u please add buy / sell condition to the above afl for scanning purpose and post it entirely. That would be great effort from your end.

Regards, MoHaN.
 

zunayed

New Member
Joined
Sep 15, 2009
Messages
12
Likes
4
#17
Hi Mohan.sic,
please add the below two line at the end of the code.

Buy = Col > 4.50 AND fon == 1 AND Ref(RSI(14),-1) < 35;
Sell = Col < 4.50 AND Fon == 1 AND Ref(RSI(14),-1) > 65;
 

yogesh-tiwari

Active Member
Joined
Aug 17, 2008
Messages
70
Likes
143
Location
Delhi
#19
I read a book "Come into my trading room".

Divergence Excerpt:

Whenever you see divergence, and price confirms by closing above the high of last candle get into trade with a stop just below the recent pivot low.

Now, the point worth noting here is..if the divergence fails and price falls back..take the opposite trade at the stop. As quoted in the book..whenever price fails a divergence, it causes "Hounds of Baskerville" to blow, whereby leading continuation of previous trend.

Rest...test and assure self.
 

mohan.sic

Well-Known Member
Joined
Jul 2, 2009
Messages
3,293
Likes
5,453
#20
Dear Zunayed,

The Buy/ sell condition for RSI divergence afl which you have given are not working.
If its working with you, please post the entire code.

Thank you, MoHaN.
 

Similar threads

Broker Special Offers