Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Divergence Detector for Amibroker (AFL)

Rating:
4 / 5 (Votes 12)
Tags:
amibroker, exploration

To explore divergence

Screenshots

Similar Indicators / Formulas

General Market Exploration by XeL
Submitted by xel over 11 years ago
Scanning Gap Up and Gap Down
Submitted by vinodsk over 10 years ago
Deel - Average Dollar Price Volatility
Submitted by kaiji about 14 years ago
Vol Peak 5 Day [Scan only]
Submitted by lusmomoney over 10 years ago
TEMA_Regression Crossover
Submitted by marcheur over 10 years ago

Indicator / Formula

Copy & Paste Friendly
SetChartOptions(3,chartGridMiddle);
SetChartOptions(0,chartShowArrows|chartShowDates); 
EnableTextOutput(False); 
mfyperiod=Param("MFI period",14,5,100);
rsyperiod=Param("RSI period",14,5,100);

procedure CalDivergence()
{
global stchbulld;
global stchbeard;
global rsybulld;
global rsybeard;
global mfybulld;
global mfybeard;
global ispeak;
global istrough;

zzg=Zig(C,5);
// find the Peaks and trough of Close
ispeak=zzg>Max(Ref(zzg,-1),Ref(zzg,1));
istrough=zzg<Min(Ref(zzg,-1),Ref(zzg,1));


// Get the value of Price At Peaks
yp2=LastValue(ValueWhen(ispeak,C,2));
yp1=LastValue(ValueWhen(ispeak,C,1));

//yp2=(ValueWhen(ispeak,C,2));
//yp1=(ValueWhen(ispeak,C,1));

// Get the value of Price At Troughs
yb2=LastValue(ValueWhen(istrough,C,2));
yb1=LastValue(ValueWhen(istrough,C,1));

//yb2=(ValueWhen(istrough,C,2));
//yb1=(ValueWhen(istrough,C,1));

stchbulld=(yb1<yb2)*(LastValue(ValueWhen(istrough,StochK(15,3),1))>LastValue(ValueWhen(istrough,StochK(15,3),2)));
stchbeard=(yp1>yp2)*(LastValue(ValueWhen(ispeak,StochK(15,3),1))<LastValue(ValueWhen(ispeak,StochK(15,3),2)));

rsybulld=(yb1<yb2)*(LastValue(ValueWhen(istrough,RSI(rsyperiod),1))>LastValue(ValueWhen(istrough,RSI(rsyperiod),2)));
rsybeard=(yp1>yp2)*(LastValue(ValueWhen(ispeak,RSI(rsyperiod),1))<LastValue(ValueWhen(ispeak,RSI(rsyperiod),2)));

mfybulld=(yb1<yb2)*(LastValue(ValueWhen(istrough,MFI(mfyperiod),1))>LastValue(ValueWhen(istrough,MFI(mfyperiod),2)));
mfybeard=(yp1>yp2)*(LastValue(ValueWhen(ispeak,MFI(mfyperiod),1))<LastValue(ValueWhen(ispeak,MFI(mfyperiod),2)));

}
procedure DrawPrice()
{
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", colorBlack, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
x=Cum(1);
// Get the x-ordinate of Close at Peaks
xp1=LastValue(ValueWhen(ispeak,x,1))-1;
xp2=LastValue(ValueWhen(ispeak,x,2))-1;
//Get the x-ordinate of Close at Troughs
xb1=LastValue(ValueWhen(istrough,x,1))-1;
xb2=LastValue(ValueWhen(istrough,x,2))-1;

// Get the value of Price At Peaks
yp2=LastValue(ValueWhen(ispeak,C,2));
yp1=LastValue(ValueWhen(ispeak,C,1));
// Get the value of Price At Troughs
yb2=LastValue(ValueWhen(istrough,C,2));
yb1=LastValue(ValueWhen(istrough,C,1));


PlotShapes(IIf(x==xb1+1,shapeStar,shapeNone),colorDarkGreen,0,L,-8);
//PlotShapes(IIf(istrough,shapeStar,shapeNone),colorDarkGreen,0,L,-8);
PlotShapes(IIf(x==xb2+1,shapeStar,shapeNone),colorDarkGreen,0,L,-8);
PlotShapes(IIf(x==xp1+1,shapeStar+shapePositionAbove,shapeNone),colorRed,0,H,-8);
PlotShapes(IIf(x==xp2+1,shapeStar+shapePositionAbove,shapeNone),colorRed,0,H,-8);

}


CalDivergence();
DrawPrice();

Filter=mfybulld+mfybeard+rsybulld+rsybeard+stchbulld+stchbeard;
AddColumn(mfybulld,"MFI Bull.D");
AddColumn(mfybeard,"MFI Bearish");

AddColumn(rsybulld,"RSI Bull.D");
AddColumn(rsybeard,"RSI Bearish");

AddColumn(stchbulld,"Stoch Bull.D");
AddColumn(stchbeard,"Stoch Bearish");

5 comments

1. eurosiva

Very good afl, can scanning be done when there is a star shown in the chart.

2. gholamreza

good*…

3. shariful

One of my very favorite afl. Frankly speaking I don’t trust any afl but this one is exception which is worthy to draw respect. Thanks lot for sharing. I would request the author or any coder to add scan option which would be greatly beneficial for a layman like me.From explore report it is really time killing and annoying to find out the potential stocks. thanks in advance.

4. chatpurpose

appears nice, but the usage of zig function requires careful evaluation, it seems.

5. thangnd.1211

very nice, thank you !

Leave Comment

Please login here to leave a comment.

Back