Afl coding rsi divergence

#1
The Below mentioned AFL Code needs a Scanner , so that at the end of the day when i run the Scan it should automatically throw a from a Group of Stocks which Stocks have qualified for the conditions.

It is based on RSI Divergence, and works beautifuilly on EOD.

It is not my own creation and was downloaded from some site, however it gives u good results in terms Filtering of tradeable ideas for next day.

Help from the experts will be really appreciated.







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

amitrandive

Well-Known Member
#2
The Below mentioned AFL Code needs a Scanner , so that at the end of the day when i run the Scan it should automatically throw a from a Group of Stocks which Stocks have qualified for the conditions.

It is based on RSI Divergence, and works beautifuilly on EOD.

It is not my own creation and was downloaded from some site, however it gives u good results in terms Filtering of tradeable ideas for next day.

Help from the experts will be really appreciated.


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);
.
.
.


100, "Sig", colorRed, styleHistogram + styleThick + styleNoLabel);
Try this, it should work

Code:
// --------------------------------------------
// 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);

p3 = ValueWhen(f, Ref(trendZig2, -1), 1);
p4 = ValueWhen(f, Ref(trendZig2, -1), 2);
r3 = ValueWhen(f, Ref(trendMom,-1), 1);
r4 = ValueWhen(f, Ref(trendMom,-1), 2);

f = r3 < r4 AND p3 > p4;

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

_N(str = "(" + period + ")");
Plot(sig * 100, "Sig", colorRed, styleHistogram + styleThick + styleNoLabel); 
f4=r1 > r2 AND p1 < p2;
f5=r3 < r4 AND p3 > p4;
BulDiv= f4 AND NOT Ref(f4, -1) AND trendMom > Ref(trendMom, -1);
BearDiv=f5 AND NOT Ref(f5, -1) AND trendMom < Ref(trendMom, -1);
Filter = BulDiv OR BearDiv;
AddColumn(Close,"Close",1.2);
AddColumn(IIf(BulDiv, BuyPrice, 0),  "Bullish Divergence", 6.2);
AddColumn(IIf(BearDiv, SellPrice, 0),  "Bearish Divergence", 6.2);
 

Similar threads