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

Gann level Plotter for Amibroker (AFL)

Rating:
5 / 5 (Votes 2)
Tags:
amibroker, gann

//You can do any of the following:
//Suppress candle or bar plotting
//Choose to plot candle or bar
//Show the Gann angle projections from Highs, Lows or Peaks and Troughs
//(the latter can be delayed in appearance because of the Amibroker fn limitation)
//Extend the Gann angle range by changing the Gann Range
// Current settings will work for scrips that are in the range of the Nifty
//Show the Angle number from 0 – 6. Useful for you to decide your trading rules.

Similar Indicators / Formulas

GANN Levels with TGT & SL
Submitted by niladri about 12 years ago
Gann Trend Chart 1
Submitted by walid over 13 years ago
PRICE GANN STYLE
Submitted by sahasra over 13 years ago
Fibonacci And Gann Projections
Submitted by ankit dargan almost 14 years ago
SUPERcam
Submitted by jaipal7786 about 10 years ago
GANN TREND (tiger)
Submitted by tigernifty about 12 years ago

Indicator / Formula

Copy & Paste Friendly
//Gann level Plotter
//Abnash Singh 5-11-2011
//abnash1978@yahoo.co.uk
//You can do any of the following:
//Suppress candle or bar plotting
//Choose to plot candle or bar
//Show the Gann angle projections from Highs, Lows or Peaks and Troughs 
//(the latter can be delayed in appearance because of the Amibroker fn limitation)
//Extend the Gann angle range by changing the Gann Range
// Current settings will work for scrips that are in the range of the Nifty
//Show the Angle number from 0 - 6. Useful for you to decide your trading rules.

//Gann logic begin
SetBarsRequired( 5000, 0 );  

showcandlechart=ParamList("Show Candle chart","YES|NO");
stylecndl=ParamList("Bar/Candle chart","BAR|CANDLE");
SHowGann=ParamList("Show Gann Angles","No|Yes",1);
SHowGannlev=ParamList("Show Gann Angles Level","No|Yes");
MArkpktr=ParamList("Mark the Highs/Lows","No|Yes");

Gann=ParamList("GannAngles","High|Low|Peak|Trough");
gannrange=Param("Gann Range",25,1,200,1);
pkno=Param("Peak Number",1,1,100,1);
perchange=Param("Zig change %",0.2,0.1,1,0.01);
BarColor		= IIf(Close > Open, colorGreen, colorRed);
SetBarFillColor(BarColor);
if (stylecndl=="BAR")stylec=styleBar;
else stylec=styleCandle;
if (showcandlechart=="YES")
{
	
	Plot(C, "Close", colorWhite, styleNoTitle | stylec); 
}

avp=(O+C)/2;
tn=TimeNum();
Datex=DateNum();
Dayhigh=Daylow=Dayopen=Dayclose=0;
Minlow=Minhigh=mint=intvl=0;
gline0=gline1=gline2=gline3=gline4=gline5=gline6=gline7=gline8=0;

pk=Peak(H,perchange,1);
pkbars=PeakBars(H,perchange,1);
Tr=Trough(L,perchange,1);
trbars=TroughBars(L,perchange,1);
intvl=Interval()/60;
Clevel=0;
Hv=HHV(H,pkno);
Lv=LLV(L,pkno);
Hvbars=BarsSince(Hv==H);
Lvbars=BarsSince(Lv==L);
pi=3.1415926;
Mint=DayOfYear()*10000+Hour()*60+Minute();
entryprice=0;
for (i=1;i<BarCount;i++)
{


//day high low
	if (Datex[i]!=Datex[i-1])
	{
		Dayhigh[i]=H[i];
		Daylow[i]=L[i];
		Minlow[i]=Mint[i];
		Minhigh[i]=Mint[i];
	}
	else 
	{
		Dayhigh[i]=Dayhigh[i-1];
		Daylow[i]=Daylow[i-1];
		Minlow[i]=Minlow[i-1];
		Minhigh[i]=Minhigh[i-1];

		if (H[i]>Dayhigh[i])
		{
			Dayhigh[i]=H[i];
			Minhigh[i]=Mint[i];
		}
		if (L[i]<Daylow[i])
		{
			Daylow[i]=L[i];
			Minlow[i]=Mint[i];
		}
	}
//Gan Fan analysis
if (pkbars[i]==0 AND gann!="Low" AND Gann!="High")gann="Peak";
if (trbars[i]==0 AND gann!="Low" AND gann!="High")gann="Trough";

Minsincehi=int(Mint[i]/intvl)*intvl-Minhigh[i];
Minsincelo=int(Mint[i]/intvl)*intvl-Minlow[i];
dh=Dayhigh[i];
dl=daylow[i];
if (gann=="Peak")
{
	dh=pk[i];
	Minsincehi=intvl*pkbars[i];
}
else if (gann=="Trough")
{
	dl=tr[i];
	Minsincelo=intvl*trbars[i];
}

if (MArkpktr=="Yes")
{
	if (dh==H[i] AND (gann=="High" OR gann=="Peak"))PlotText("P",i,H[i]+5,colorOrange);
	if (dl==L[i] AND (gann=="Low" OR gann=="Trough"))PlotText("T",i,L[i]-5,colorOrange);
}


if ((gann=="High" OR gann=="Peak") AND Minsincehi>0)
{
	gline0[i]=dh-((minsincehi)*tan(0*90*pi/180));
	gline1[i]=dh-((minsincehi)*tan(0.125*90*pi/180));
	gline2[i]=dh-((minsincehi)*tan(0.25*90*pi/180));
	gline3[i]=dh-((minsincehi)*tan(0.382*90*pi/180));
	gline4[i]=dh-((minsincehi)*tan(0.5*90*pi/180));
	gline5[i]=dh-((minsincehi)*tan(0.618*90*pi/180));
	gline6[i]=dh-((minsincehi)*tan(0.75*90*pi/180));
	gline7[i]=dh-((minsincehi)*tan(0.875*90*pi/180));
	gline8[i]=dh-((minsincehi)*tan(1*90*pi/180));
	if (gline1[i]<dh-gannrange)gline1[i]=Null;
	if (gline2[i]<dh-gannrange)gline2[i]=Null;
	if (gline3[i]<dh-gannrange)gline3[i]=Null;
	if (gline4[i]<dh-gannrange)gline4[i]=Null;
	if (gline5[i]<dh-gannrange)gline5[i]=Null;
	if (gline6[i]<dh-gannrange)gline6[i]=Null;
	if (gline7[i]<dh-gannrange)gline7[i]=Null;
	if (gline8[i]<dh-gannrange)gline8[i]=Null;
}
else if ((gann=="Low" OR gann=="Trough") AND Minsincelo>0)
{
	gline0[i]=dl+((minsincelo)*tan(0*90*pi/180));
	gline1[i]=dl+((minsincelo)*tan(0.125*90*pi/180));
	gline2[i]=dl+((minsincelo)*tan(0.25*90*pi/180));
	gline3[i]=dl+((minsincelo)*tan(0.382*90*pi/180));
	gline4[i]=dl+((minsincelo)*tan(0.5*90*pi/180));
	gline5[i]=dl+((minsincelo)*tan(0.618*90*pi/180));
	gline6[i]=dl+((minsincelo)*tan(0.75*90*pi/180));
	gline7[i]=dl+((minsincelo)*tan(0.875*90*pi/180));
	gline8[i]=dl+((minsincelo)*tan(1*90*pi/180));
	if (gline1[i]>dl+gannrange)gline1[i]=Null;
	if (gline2[i]>dl+gannrange)gline2[i]=Null;
	if (gline3[i]>dl+gannrange)gline3[i]=Null;
	if (gline4[i]>dl+gannrange)gline4[i]=Null;
	if (gline5[i]>dl+gannrange)gline5[i]=Null;
	if (gline6[i]>dl+gannrange)gline6[i]=Null;
	if (gline7[i]>dl+gannrange)gline7[i]=Null;
	if (gline8[i]>dl+gannrange)gline8[i]=Null;
}
else 
{
gline0[i]=gline1[i]=gline2[i]=gline3[i]=gline4[i]=gline5[i]=gline6[i]=gline7[i]=gline8[i]=Null;
}


x=0;
if (gline0[i]>gline2[i])
	if (C[i]<gline0[i])
		if (C[i]<gline1[i])
			if (C[i]<gline2[i])
				if (C[i]<gline3[i])
					if (C[i]<gline4[i])
						if (C[i]<gline5[i])
							if (C[i]<gline6[i])
								if (gline0[i]>0)x=6;
								else x=1; 
							else if (gline0[i]>0)x=5;
								else x=1;
						else if (gline0[i]>0)x=4;
							else x=1;	
				else if (gline0[i]>0)x=3;
						else x=1;
			else if (gline0[i]>0)x=2;
					else x=1;
		else if (gline0[i]>0)x=1;

if (gline2[i]>gline0[i])
	if (C[i]>gline0[i])
		if (C[i]>gline1[i])
			if (C[i]>gline2[i])
				if (C[i]>gline3[i])
					if (C[i]>gline4[i])
						if (C[i]>gline5[i])
							if (C[i]>gline6[i])
								if (gline0[i]>0)x=6;
								else x=1;
							else if (gline0[i]>0)x=5;
								else x=1;
						else if (gline0[i]>0)x=4;
							else x=1;	
				else if (gline0[i]>0)x=3;
						else x=1;
			else if (gline0[i]>0)x=2;
					else x=1;
		else if (gline0[i]>0)x=1;

if (x==1)
{
	entryprice[i]=gline1[i];
	Clevel[i]=1+(abs(gline1[i]-C[i]))/(abs(gline1[i]-gline2[i]));
}
if (x==2)
{
	entryprice[i]=gline2[i];
	Clevel[i]=2+(abs(gline2[i]-C[i]))/(abs(gline2[i]-gline3[i]));

}
if (x==3)
{
	entryprice[i]=gline3[i];
	Clevel[i]=3+(abs(gline3[i]-C[i]))/(abs(gline3[i]-gline4[i]));
}
if (x==4)
{	
	entryprice[i]=gline4[i];
	Clevel[i]=4+(abs(gline4[i]-C[i]))/(abs(gline4[i]-gline5[i]));

}
if (x==5)
{
	entryprice[i]=gline5[i];
	Clevel[i]=5+(abs(gline5[i]-C[i]))/(abs(gline5[i]-gline6[i]));

}
if (x==6)
{
	entryprice[i]=gline6[i];
	Clevel[i]=6+(abs(gline6[i]-C[i]))/(abs(gline6[i]-gline7[i]));
}
if (showgannlev=="Yes")
{

if (x==0 AND 
			(((gann=="High" OR gann=="peak") AND C[i]<gline0[i]) OR
			 ((gann=="Low" OR gann=="Trough") AND C[i]>gline0[i])) )PlotText("0",i,H[i]+25,colorWhite);
if (x==1)PlotText("1",i,H[i]+25,colorWhite);
if (x==2)PlotText("2",i,H[i]+25,colorWhite);
if (x==3)PlotText("3",i,H[i]+25,colorWhite);
if (x==4)PlotText("4",i,H[i]+25,colorWhite);
if (x==5)PlotText("5",i,H[i]+25,colorWhite);
if (x==6)PlotText("6",i,H[i]+25,colorWhite);

}


}//Gan fan analysis end

Colorpnk=ColorRGB(150,75,75);
Colorblu=ColorRGB(25,100,150);
Colorylo=ColorRGB(150,150,50);


if (showgann=="Yes")
{
	Plot(gline0,"0 deg",Colorpnk,styleLine|styleNoLabel);
	Plot(gline1,"12.5 deg",Colorblu,styleLine|styleNoLabel);
	Plot(gline2,"25 deg",Colorylo,styleLine|styleNoLabel);
	Plot(gline3,"38.2 deg",Colorblu,styleLine|styleNoLabel);
	Plot(gline4,"45 deg",Colorpnk,styleLine|styleNoLabel);
	Plot(gline5,"61.8 deg",Colorblu,styleLine|styleNoLabel);
	Plot(gline6,"75 deg",Colorylo,styleLine|styleNoLabel);
	Plot(gline7,"87.5 deg",Colorblu,styleLine|styleNoLabel);
}

4 comments

1. cjsheth41

Sirji request you to kindly let us know as to how do we interprate this gann levels am not sure how to read the results and we see no levels on daily basis and above

2. anandnst

anand ji,
would u please give more interpretation abt this AFL..

Thanx you

3. carlvan

Superb!

4. carlvan

I had a question: this code is made to fit more or less Nifty prices, as you well indicated in the code. When you use it on daily charts or for other symbols, it doesn’t plot.
Could you please indicate where in the code some constant needs to be changed? Thank you.

Leave Comment

Please login here to leave a comment.

Back