AFL Correction - Gann Sq of 9

#1
Hi All memebers,

I found an AFL from net plotting lines for levels of Gann Square of 9.

I am trying to make changes so that lines show up only for current day. And just 3 lines above and 3 lines below the previous days close.

AFL seems to be very tricky for me. Please help me.

-------------------------------------------


_SECTION_BEGIN("gann_levels_plot_with_targets_and_day_highlow");
//Gann level Plotter
//Abnash Singh 5-11-2011
//Updated on 12-11-2011 to include context based Gann levels and days highs and lows
//[email protected]
//You can do any of the following:
//Suppress candle or bar plotting
//Choose to plot candle or bar
//Choose to plot 0/90 deg levels or also 45/225 and 135/315 deg levels
//Clip plotting from 15:25-15:30 to avoid clutter on day change
//Clip Gann lines outside the price range.
//Gann logic begin
SetBarsRequired( 5000, 0 );

showcandlechart=ParamList("Show Candle chart","YES|NO");
stylecndl=ParamList("Bar/Candle chart","BAR|CANDLE");
PlotGann=ParamList("Show Gann Lines","Yes|No",0);
PlotGannBlue=ParamList("Show Gann Blue Lines","Yes|No",0);
PlotGannRed=ParamList("Show Gann Red Lines","Yes|No",0);
PlotGannodd=ParamList("Show Gann Odd Angle Lines","Yes|No",1);
ClipGann=ParamList("Clip Gann Lines above High/Low","Yes|No",1);
Clip1530=ParamList("Clip Lines at time 1530","Yes|No",1);


GannProx=ParamList("Gann to Mid price < 5 pts","Yes|No",1);

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

//avp=(O+C)/2;
avp=C;
tn=TimeNum();
Datey=DateNum();
gannh0=gannh1=gannh2=gannh3=gannh4=gannh5=gannh6=gannh7=gannh8=Null;
gannl0=gannl1=gannl2=gannl3=gannl4=gannl5=gannl6=gannl7=gannl8=Null;
gannmin=0;basec=basenoh=basenol=0;
gannmin=0;
Dayhigh=Daylow=Dayopen=Dayclose=0;
uptarget=lotarget=0;
for (i=1;i<BarCount;i++)
{

//day high low logic
if (Datey!=Datey[i-1])
{
ds=i;pkmax=trmin=0;
Dayopen=C;
Dayclose=C;
}
if (Datey==Datey[i-1])
{
Dayopen=Dayopen[i-1];
Dayclose=Dayclose[i-1];
Dayhigh=Dayhigh[i-1];
Daylow=Daylow[i-1];
}

if (H>Dayhigh)Dayhigh=H;
if (Daylow==0)Daylow=L;
if (L<Daylow)Daylow=L;





if (PlotGann=="Yes")
{
dnn=30;
basenoh=int(sqrt(dayopen));
basenol=int(sqrt(C));



//PlotText(WriteVal(basenol,1.0),i,H+5,colorWhite);

gannh0=basenoh*basenoh;
gannh1=(basenoh+0.125)^2;
gannh2=(basenoh+0.25)^2;
gannh3=(basenoh+0.375)^2;
gannh4=(basenoh+0.5)^2;
gannh5=(basenoh+0.625)^2;
gannh6=(basenoh+0.75)^2;
gannh7=(basenoh+0.875)^2;
gannh8=(basenoh+1)^2;

if(basenoh!=basenol) gannl0=basenol*basenol;
if(basenoh!=basenol) gannl1=(basenol+0.125)^2;
if(basenoh!=basenol) gannl2=(basenol+0.25)^2;
if(basenoh!=basenol) gannl3=(basenol+0.375)^2;
if(basenoh!=basenol) gannl4=(basenol+0.5)^2;
if(basenoh!=basenol) gannl5=(basenol+0.625)^2;
if(basenoh!=basenol) gannl6=(basenol+0.75)^2;
if(basenoh!=basenol) gannl7=(basenol+0.875)^2;
if(basenoh!=basenol) gannl8=Null;//(basenol+1)^2;
if(ClipGann=="Yes")
{
if (gannh0>Dayhigh+dnn OR gannh0<Daylow-dnn)gannh0=Null;
if (gannh1>Dayhigh+dnn OR gannh1<Daylow-dnn)gannh1=Null;
if (gannh2>Dayhigh+dnn OR gannh2<Daylow-dnn)gannh2=Null;
if (gannh3>Dayhigh+dnn OR gannh3<Daylow-dnn)gannh3=Null;
if (gannh4>Dayhigh+dnn OR gannh4<Daylow-dnn)gannh4=Null;
if (gannh5>Dayhigh+dnn OR gannh5<Daylow-dnn)gannh5=Null;
if (gannh6>Dayhigh+dnn OR gannh6<Daylow-dnn)gannh6=Null;
if (gannh7>Dayhigh+dnn OR gannh7<Daylow-dnn)gannh7=Null;
if (gannh8>Dayhigh+dnn OR gannh8<Daylow-dnn)gannh8=Null;
if (gannl0>Dayhigh+dnn OR gannl0<Daylow-dnn)gannl0=Null;
if (gannl1>Dayhigh+dnn OR gannl1<Daylow-dnn)gannl1=Null;
if (gannl2>Dayhigh+dnn OR gannl2<Daylow-dnn)gannl2=Null;
if (gannl3>Dayhigh+dnn OR gannl3<Daylow-dnn)gannl3=Null;
if (gannl4>Dayhigh+dnn OR gannl4<Daylow-dnn)gannl4=Null;
if (gannl5>Dayhigh+dnn OR gannl5<Daylow-dnn)gannl5=Null;
if (gannl6>Dayhigh+dnn OR gannl6<Daylow-dnn)gannl6=Null;
if (gannl7>Dayhigh+dnn OR gannl7<Daylow-dnn)gannl7=Null;
if (gannl7>Dayhigh+dnn OR gannl7<Daylow-dnn)gannl7=Null;
}

//if (IsNull(gannh8))PlotText(WriteVal(1,1.0),i,L-5,colorOrange);

//else
if (Clip1530=="Yes" AND tn>=153000 AND tn<=153500)
gannh0= gannh1= gannh2= gannh3= gannh4= gannh5= gannh6= gannh7= gannh8=
gannl0= gannl1= gannl2= gannl3= gannl4= gannl5= gannl6= gannl7= gannl8=
Null;
//Gann logic end

// is price close to a Gann Line?

gannmin=100000;
if (!IsNull(gannh0))
gannmin=Min (gannmin, abs(gannh0-avp));
if (!IsNull(gannh2))
gannmin=Min (gannmin, abs(gannh2-avp));
if (!IsNull(gannh4))
gannmin=Min (gannmin, abs(gannh4-avp));
if (!IsNull(gannh6))
gannmin=Min (gannmin, abs(gannh6-avp));
if (!IsNull(gannh8))
gannmin=Min (gannmin, abs(gannh8-avp));
if (!IsNull(gannl0))
gannmin=Min (gannmin, abs(gannl0-avp));
if (!IsNull(gannl2))
gannmin=Min (gannmin, abs(gannl2-avp));
if (!IsNull(gannl4))
gannmin=Min (gannmin, abs(gannl4-avp));
if (!IsNull(gannl6))
gannmin=Min (gannmin, abs(gannl6-avp));
if (!IsNull(gannl8))
gannmin=Min (gannmin, abs(gannl8-avp));
if (gannprox=="Yes" AND gannmin<5 AND gannmin<gannmin[i-1])PlotText(" ^",i,L-5,colorOrange);

if (Plotgannodd=="Yes" AND PlotGannRed=="Yes" AND PlotGannBlue=="Yes" AND PlotGann=="Yes")
{
if (avp<gannh8 AND avp>gannh7){uptarget=gannh8; Lotarget=gannh7;}
if (avp<gannh7 AND avp>gannh6){uptarget=gannh7; Lotarget=gannh6;}
if (avp<gannh6 AND avp>gannh5){uptarget=gannh6; Lotarget=gannh5;}
if (avp<gannh5 AND avp>gannh4){uptarget=gannh5; Lotarget=gannh4;}
if (avp<gannh4 AND avp>gannh3){uptarget=gannh4; Lotarget=gannh3;}
if (avp<gannh3 AND avp>gannh2){uptarget=gannh3; Lotarget=gannh2;}
if (avp<gannh2 AND avp>gannh1){uptarget=gannh2; Lotarget=gannh1;}
if (avp<gannh1 AND avp>gannh0){uptarget=gannh1; Lotarget=gannh0;}
if (avp<gannh0 AND avp>gannl7){uptarget=gannh0; Lotarget=gannl7;}
if (avp<gannl8 AND avp>gannl7){uptarget=gannl8; Lotarget=gannl7;}
if (avp<gannl7 AND avp>gannl6){uptarget=gannl7; Lotarget=gannl6;}
if (avp<gannl6 AND avp>gannl5){uptarget=gannl6; Lotarget=gannl5;}
if (avp<gannl5 AND avp>gannl4){uptarget=gannl5; Lotarget=gannl4;}
if (avp<gannl4 AND avp>gannl3){uptarget=gannl4; Lotarget=gannl3;}
if (avp<gannl3 AND avp>gannl2){uptarget=gannl3; Lotarget=gannl2;}
if (avp<gannl2 AND avp>gannl1){uptarget=gannl2; Lotarget=gannl1;}
if (avp<gannl1 AND avp>gannl0){uptarget=gannl1; Lotarget=gannl0;}
}
if (Plotgannodd=="No" AND PlotGannRed=="Yes" AND PlotGannBlue=="Yes" AND PlotGann=="Yes")
{
if (avp<gannh8 AND avp>gannh6){uptarget=gannh8; Lotarget=gannh6;}
if (avp<gannh6 AND avp>gannh4){uptarget=gannh6; Lotarget=gannh4;}
if (avp<gannh4 AND avp>gannh2){uptarget=gannh5; Lotarget=gannh2;}
if (avp<gannh2 AND avp>gannh0){uptarget=gannh4; Lotarget=gannh0;}
if (avp<gannh0 AND avp>gannl6){uptarget=gannh0; Lotarget=gannl6;}
if (avp<gannl8 AND avp>gannl6){uptarget=gannl8; Lotarget=gannl6;}
if (avp<gannl6 AND avp>gannl4){uptarget=gannl6; Lotarget=gannl4;}
if (avp<gannl4 AND avp>gannl2){uptarget=gannl4; Lotarget=gannl2;}
if (avp<gannl2 AND avp>gannl0){uptarget=gannl2; Lotarget=gannl0;}
}
if (Plotgannodd=="No" AND PlotGannRed=="No" AND PlotGannBlue=="Yes" AND PlotGann=="Yes")
{
if (avp<gannh8 AND avp>gannh4){uptarget=gannh8; Lotarget=gannh4;}
if (avp<gannh4 AND avp>gannh0){uptarget=gannh4; Lotarget=gannh0;}
if (avp<gannh0 AND avp>gannl4){uptarget=gannh0; Lotarget=gannl4;}
if (avp<gannl8 AND avp>gannl4){uptarget=gannl8; Lotarget=gannl4;}
if (avp<gannl4 AND avp>gannl0){uptarget=gannl4; Lotarget=gannl0;}
}
if (Plotgannodd=="No" AND PlotGannRed=="No" AND PlotGannBlue=="No" AND PlotGann=="Yes")
{
if (avp<gannh8 AND avp>gannh0){uptarget=gannh8; Lotarget=gannh0;}
if (avp<gannh0 AND avp>gannl0){uptarget=gannh0; Lotarget=gannl0;}
}

}


}

if (Plotgann=="Yes")
{
for (i=0;i<=8;i++)
{
if (i==0 OR i==8)
{
Plot(VarGet("gannh"+i),"Gannh"+i,colorWhite,styleLine|styleDashed|styleNoTitle+styleNoRescale);
Plot(VarGet("gannl"+i),"Gannl"+i,colorWhite,styleLine|styleDashed|styleNoTitle+styleNoRescale);
}
if ((i==2 OR i==6) AND PlotGannRed=="Yes")
{
Plot(VarGet("gannh"+i),"Gannh"+i,colorRed,styleLine|styleDashed|styleNoTitle+styleNoRescale);
Plot(VarGet("gannl"+i),"Gannl"+i,colorRed,styleLine|styleDashed|styleNoTitle+styleNoRescale);
}
if (i==4 AND PlotGannBlue=="Yes")
{
Plot(VarGet("gannh"+i),"Gannh"+i,colorBlue,styleLine|styleDashed|styleNoTitle+styleNoRescale);
Plot(VarGet("gannl"+i),"Gannl"+i,colorBlue,styleLine|styleDashed|styleNoTitle+styleNoRescale);
}


if (Plotgannodd=="Yes")
{
if (i==1 OR i==3 OR i==5 OR i==7)
{
Plot(VarGet("gannh"+i),"Gannh"+i,colorGreen,styleLine|styleDashed|styleNoTitle+styleNoRescale);
Plot(VarGet("gannl"+i),"Gannl"+i,colorGreen,styleLine|styleDashed|styleNoTitle+styleNoRescale);
}
}
}
}



_SECTION_END();
 
Last edited:

Similar threads

Broker Special Offers

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

Name:Phone:
Email:City:
State:
Are you a day trader?