Gann Strategy AFL - Enjoy

myamit

Well-Known Member
#11
The main part of Gann calculations is coded by "Myamit" . So all credit goes to him. I have modified Buy Short and profit booking conditions according to my convenience. ...
Hello Rajvir,

Great to see your post and initiative. Hope you are getting good success with your method.

Also, thank you for the credits. Please feel free should you need any help wth AFL.

Regards,
 
#12
I changed the parameter under intraday tab and now the code work well.I didn't changed any line of code. I use amibroker 5.40
Now, only things to do is to watch if the TS work well.
I want to test it on nasadaq future. Do you think that can be good?
me tooo the same proplem mr Rajvir
 

myamit

Well-Known Member
#13
Hello,

This is for all those who are getting emply numbers. Please change reftime var.

change
reftime = 092900;

as
reftime = 092959;

Revised code is as below...

Code:
SetChartOptions(0,chartShowArrows|chartShowDates,colorRed);


Plot(C,"Price",IIf(C>O,colorBrightGreen,colorBrown),styleCandle);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L,C, SelectedValue( ROC( C, 1 )) ));


_SECTION_END(); 




_SECTION_BEGIN("GaNN Square of Nine");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

TodayVolume = Sum(V,BarsToday);

VWAP = (Sum (((C+O+H+L)/4) * V, BarsToday ) / TodayVolume);
Plot (VWAP,"VWAP",colorBlue, styleStaircase = 512);

reftime = 092900;
RefVWAP = ValueWhen(TimeNum() == reftime, Vwap,1);


BaseNum = (int(sqrt(RefVWAP))-1);
sBelow = BaseNum + BaseNum;
sBelowI = 1;


//Calculate levels for GANN Square of Nine

for( i = 1; i < 50; i++ ) 
{ 
VarSet( "GANN"+i, (BaseNum * BaseNum) ); 
BaseNum = BaseNum + 0.125;
sBelowI = IIf( VarGet("GANN"+i)< RefVWAP, i, sBelowI);
bAboveI = sBelowI + 1;
sBelow = round(VarGet("GANN"+sBelowI));
bAbove =  round(VarGet("GANN"+bAboveI));
}

// Resistance Levels (or Targets for Buy trade)
BTgt1 = round(0.9995 * VarGet("Gann"+(bAboveI+1)));
BTgt2 = round(0.9995 * VarGet("Gann"+(bAboveI+2)));
BTgt3 = round(0.9995 * VarGet("Gann"+(bAboveI+3)));
BTgt4 = round(0.9995 * VarGet("Gann"+(baboveI+4)));
BTgt5 = round(0.9995 * VarGet("Gann"+(bAboveI+5)));
BTgt6 = round(0.9995 * VarGet("Gann"+(baboveI+6)));
// Support Levels (or Targets for Short trade)
STgt1 = round(1.0005 * VarGet("Gann"+(sBelowI-1)));
STgt2 = round(1.0005 * VarGet("Gann"+(sBelowI-2)));
STgt3 = round(1.0005 * VarGet("Gann"+(sBelowI-3)));
STgt4 = round(1.0005 * VarGet("Gann"+(sbelowI-4)));
STgt5 = round(1.0005 * VarGet("Gann"+(sBelowI-5)));
STgt6 = round(1.0005 * VarGet("Gann"+(sBelowI-6)));

Sstop= round(babove-((babove-sbelow)/3)) ;
Bstop= round(sbelow+((babove-sbelow)/3)) ;

BuySignal = TimeNum()>reftime AND (Cross(H,babove)OR Cross(C,babove) OR (H>babove AND L<=babove))  AND VWAP<babove ;
ShortSignal = TimeNum()>reftime AND (Cross(Sbelow,L) OR Cross(Sbelow,C) OR (H>=sbelow AND L<sbelow))AND VWAP>sbelow  ;

BuySignal = ExRem(BuySignal,ShortSignal);
ShortSignal = ExRem(ShortSignal,BuySignal);

ShortProfitStop= (STgt1 AND L<=Stgt1 AND C>Stgt1) OR (STgt2 AND L<=Stgt2 AND C>Stgt2) OR (STgt3 AND L<=Stgt3 AND C>Stgt3) OR (STgt4 AND L<=Stgt4 AND C>Stgt4) OR (STgt5 AND L<=Stgt5 AND C>Stgt5) OR (STgt6 AND L<=Stgt6 AND C>Stgt6);

BuyProfitStop= (Btgt1 AND H>=btgt1 AND C<Btgt1) OR (Btgt2 AND H>=Btgt2 AND C<btgt2) OR (Btgt3 AND H>=Btgt3 AND C<btgt3) OR (Btgt4 AND H>=Btgt4 AND C<btgt4) OR (Btgt5 AND H>=Btgt5 AND C<btgt5) OR (Btgt6 AND H>=Btgt6 AND C<btgt6);

SetOption("MaxOpenPositions", 1 ); 
SetPositionSize(100,spsShares);

Buy = BuySignal;
Sell = C<Bstop OR BuyProfitStop;
Short = ShortSignal;
Cover = C>SStop OR ShortProfitStop;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);



Sstop= round(babove-((babove-sbelow)/3)) ;
Bstop= round(sbelow+((babove-sbelow)/3)) ;

GfxSetBkMode( 1 );
GfxSelectFont("Courier New", 11, 700 ); 
GfxSetTextColor( colorBrightGreen );
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorWhite ); 

BTgtext = "Buy Targets   : " + NumToStr(btgt1,1.2,False) + " - " + NumToStr(btgt2,1.2,False) + " - " + NumToStr(btgt3,1.2,False);
STgtext = "Short Targets : " + NumToStr(stgt1,1.2,False) + " - " + NumToStr(stgt2,1.2) + " - " + NumToStr(stgt3,1.2,False);

GfxTextOut("Current time  : " + TimeNum(), 225, 25);

GfxTextOut("Buy Above     : " + WriteIf(TimeNum()>reftime, NumToStr(bAbove,1.2,False) + "    SL : " + NumToStr(sBelow,1.2,False),"Waiting for Signal"), 225, 45);
GfxTextOut(WriteIf(TimeNum()>reftime,BTgtext,""), 225, 55);

GfxSetBkMode( 1 );
GfxSelectFont("courier new", 11, 700 ); 
GfxSetTextColor( colorRed );
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorWhite ); 

GfxTextOut("Short Below   : " + WriteIf(TimeNum()>reftime, NumToStr(sBelow,1.2,False) + "    SL : " + NumToStr(bAbove,1.2,False),"Waiting for Signal"), 225, 75);
GfxTextOut(WriteIf(TimeNum()>reftime,STgtext,""), 225, 85);

AddColumn(Close,"Close",1.4);
AddColumn(Buysignal,"buysignal",1.2);


_SECTION_BEGIN("BBands");
Plot(BBandTop(C,20,2),"",colorLightGrey,style=styleLine|styleNoRescale|styleNoLabel);
Plot(BBandBot(C,20,2),"",colorLightGrey,style=styleLine|styleNoLabel);
_SECTION_END();

Plot(sstop,"",colorGreen,styleDots=8|styleNoLabel);
Plot(bstop,"",colorRed,styleDots=8|styleNoLabel);
PlotOHLC( babove, sbelow, babove,sbelow, "", colorYellow, styleCloud); 
PlotOHLC( sbelow, babove, sbelow,babove, "", colorYellow, styleCloud); 




PlotShapes(IIf(Buysignal, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-20);
PlotShapes(IIf(Buysignal, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-30);                      
PlotShapes(IIf(Buysignal, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25); 

PlotShapes(IIf(Shortsignal, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Shortsignal, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);                      
PlotShapes(IIf(Shortsignal, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);

Plot(BTgt1,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt2,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt3,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt4,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt5,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt6,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);

Plot(STgt1,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt2,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt3,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt4,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt5,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt6,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);


PlotShapes(IIf(Cover, shapeHollowUpArrow,shapeNone),colorGreen, 0, Low, Offset=-20);
PlotShapes(IIf(Sell, shapeHollowDownArrow,shapeNone),colorRed, 0, High, Offset=-20);
 
#14
I modified so that it be more apparently:

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer Panel",colorLightGrey));
SetChartBkGradientFill(ParamColor("Upper Chart",colorDarkGrey),ParamColor("Lower Chart",colorDarkGrey));
GraphXSpace=Param("GraphXSpace",10,0,100,1);
dec = (Param("Decimals",2,0,7,1)/10)+1;
bi = BarIndex();
Lbi = LastValue(BarIndex());
sbi = SelectedValue(bi);
x1= BarCount-1;
Title = EncodeColor(42)+ Title = Name() +" GaNN Square"+ " " + EncodeColor(32) + Date() +
" " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(55)+ " Open = "+ EncodeColor(52)+ WriteVal(O,dec) +
EncodeColor(55)+ " High = "+ EncodeColor(5) + WriteVal(H,dec) +
EncodeColor(55)+ " Low = "+ EncodeColor(32)+ WriteVal(L,dec) +
EncodeColor(55)+ " Close = "+ EncodeColor(52)+ WriteVal(C,dec)+
EncodeColor(55)+ " Volume = "+ EncodeColor(52)+ WriteVal(V,1);

SetBarFillColor(IIf(O>C,24,19));
Plot(C,"Price",IIf(O>C,32,34),64);// bary - świece

_SECTION_END();

_SECTION_BEGIN("GaNN Square of Nine");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

TodayVolume = Sum(V,BarsToday);

VWAP = (Sum (((C+O+H+L)/4) * V, BarsToday ) / TodayVolume);
Plot (VWAP,"VWAP",colorAqua, styleStaircase|styleThick = 512);


RefVWAP = ValueWhen(TimeNum() == 092900, Vwap,1);


BaseNum = (int(sqrt(RefVWAP))-1);
sBelow = BaseNum + BaseNum;
sBelowI = 1;


//Calculate levels for GANN Square of Nine

for( i = 1; i < 50; i++ )
{
VarSet( "GANN"+i, (BaseNum * BaseNum) );
BaseNum = BaseNum + 0.125;
sBelowI = IIf( VarGet("GANN"+i)< RefVWAP, i, sBelowI);
bAboveI = sBelowI + 1;
sBelow = round(VarGet("GANN"+sBelowI));
bAbove = round(VarGet("GANN"+bAboveI));
}

// Resistance Levels (or Targets for Buy trade)
BTgt1 = round(0.9995 * VarGet("Gann"+(bAboveI+1)));
BTgt2 = round(0.9995 * VarGet("Gann"+(bAboveI+2)));
BTgt3 = round(0.9995 * VarGet("Gann"+(bAboveI+3)));
BTgt4 = round(0.9995 * VarGet("Gann"+(baboveI+4)));
BTgt5 = round(0.9995 * VarGet("Gann"+(bAboveI+5)));
BTgt6 = round(0.9995 * VarGet("Gann"+(baboveI+6)));
// Support Levels (or Targets for Short trade)
STgt1 = round(1.0005 * VarGet("Gann"+(sBelowI-1)));
STgt2 = round(1.0005 * VarGet("Gann"+(sBelowI-2)));
STgt3 = round(1.0005 * VarGet("Gann"+(sBelowI-3)));
STgt4 = round(1.0005 * VarGet("Gann"+(sbelowI-4)));
STgt5 = round(1.0005 * VarGet("Gann"+(sBelowI-5)));
STgt6 = round(1.0005 * VarGet("Gann"+(sBelowI-6)));

Sstop= round(babove-((babove-sbelow)/3)) ;
Bstop= round(sbelow+((babove-sbelow)/3)) ;

BuySignal = TimeNum()>092900 AND (Cross(H,babove)OR Cross(C,babove) OR (H>babove AND L<=babove)) AND VWAP<babove ;
ShortSignal = TimeNum()>092900 AND (Cross(Sbelow,L) OR Cross(Sbelow,C) OR (H>=sbelow AND L<sbelow))AND VWAP>sbelow ;

BuySignal = ExRem(BuySignal,ShortSignal);
ShortSignal = ExRem(ShortSignal,BuySignal);

ShortProfitStop= (STgt1 AND L<=Stgt1 AND C>Stgt1) OR (STgt2 AND L<=Stgt2 AND C>Stgt2) OR (STgt3 AND L<=Stgt3 AND C>Stgt3) OR (STgt4 AND L<=Stgt4 AND C>Stgt4) OR (STgt5 AND L<=Stgt5 AND C>Stgt5) OR (STgt6 AND L<=Stgt6 AND C>Stgt6);

BuyProfitStop= (Btgt1 AND H>=btgt1 AND C<Btgt1) OR (Btgt2 AND H>=Btgt2 AND C<btgt2) OR (Btgt3 AND H>=Btgt3 AND C<btgt3) OR (Btgt4 AND H>=Btgt4 AND C<btgt4) OR (Btgt5 AND H>=Btgt5 AND C<btgt5) OR (Btgt6 AND H>=Btgt6 AND C<btgt6);

SetOption("MaxOpenPositions", 1 );
SetPositionSize(100,spsShares);

Buy = BuySignal;
Sell = C<Bstop OR BuyProfitStop;
Short = ShortSignal;
Cover = C>SStop OR ShortProfitStop;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);



Sstop= round(babove-((babove-sbelow)/3)) ;
Bstop= round(sbelow+((babove-sbelow)/3)) ;

GfxSetBkMode( 1 );
GfxSelectFont("Arial", 12, 900 );
GfxSetTextColor( colorLime );
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorBlue );

BTgtext = "Buy Targets : " + NumToStr(btgt1,1.2,False) + " - " + NumToStr(btgt2,1.2,False) + " - " + NumToStr(btgt3,1.2,False);
STgtext = "Short Targets : " + NumToStr(stgt1,1.2,False) + " - " + NumToStr(stgt2,1.2) + " - " + NumToStr(stgt3,1.2,False);

GfxTextOut("Current time : " + TimeNum(), 10, 25);

GfxTextOut("Buy Above : " + WriteIf(TimeNum()>092900, NumToStr(bAbove,1.2,False) + " SL : " + NumToStr(sBelow,1.2,False),"Waiting for Signal"), 10, 45);
GfxTextOut(WriteIf(TimeNum()>092900,BTgtext,""), 10, 65);

GfxSetBkMode( 1 );
GfxSelectFont("Arial", 12, 900 );
GfxSetTextColor( colorOrange );
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorBlue );

GfxTextOut("Short Below : " + WriteIf(TimeNum()>092900, NumToStr(sBelow,1.2,False) + " SL : " + NumToStr(bAbove,1.2,False),"Waiting for Signal"), 10, 85);
GfxTextOut(WriteIf(TimeNum()>092900,STgtext,""), 10, 105);

AddColumn(Close,"Close",1.4);
AddColumn(Buysignal,"buysignal",1.2);

/*
_SECTION_BEGIN("BBands");
Plot(BBandTop(C,20,2),"",colorLightGrey,style=styleLine|styleNoRescale|styleNoLabel);
Plot(BBandBot(C,20,2),"",colorLightGrey,style=styleLine|styleNoLabel);
_SECTION_END();
*/

Plot(sstop,"",colorGreen,styleDots=8|styleNoLabel) ;
Plot(bstop,"",colorOrange,styleDots=8|styleNoLabel);
PlotOHLC( babove, sbelow, babove,sbelow, "", colorYellow, styleCloud);
PlotOHLC( sbelow, babove, sbelow,babove, "", colorYellow, styleCloud);

PlotShapes(IIf(Buysignal, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-20);
PlotShapes(IIf(Buysignal, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-30);
PlotShapes(IIf(Buysignal, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);

PlotShapes(IIf(Shortsignal, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Shortsignal, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
PlotShapes(IIf(Shortsignal, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);

Plot(BTgt1,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt2,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt3,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt4,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt5,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt6,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);

Plot(STgt1,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt2,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt3,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt4,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt5,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt6,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);


PlotShapes(IIf(Cover, shapeHollowUpArrow,shapeNone),colorGreen, 0, Low, Offset=-20);
PlotShapes(IIf(Sell, shapeHollowDownArrow,shapeNone),colorRed, 0, High, Offset=-20);
_SECTION_END();
 
#15
I want to ask to the ravjiri that said that he modified the original formula, where is the original. becuase i want to use it on nasdaq and i don't know if now the formula is good for this market.
 

Rajvir

Active Member
#16
I want to ask to the ravjiri that said that he modified the original formula, where is the original. becuase i want to use it on nasdaq and i don't know if now the formula is good for this market.
Nothing much changed in the origional AFL, I lost the origional but below is almost same. I modified only buy sell and profit booking conditions


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates,colorRed);


Plot(C,"Price",IIf(C>O,colorBrightGreen,colorBrown),styleCandle);






_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", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();

_SECTION_BEGIN("GaNN Square of Nine");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

TodayVolume = Sum(V,BarsToday);

VWAP = (Sum (((C+O+H+L)/4) * V, BarsToday ) / TodayVolume);




RefVWAP = ValueWhen(TimeNum() == 092900, C,1);

Plot (VWAP,"VWAP",colorBlue, styleStaircase = 512 );




BaseNum = (int(sqrt(RefVWAP))-1);
sBelow = BaseNum + BaseNum;
sBelowI = 1;

//Calculate levels for GANN Square of Nine

for( i = 1; i < 50; i++ )
{
VarSet( "GANN"+i, (BaseNum * BaseNum) );
BaseNum = BaseNum + 0.125;
sBelowI = IIf( VarGet("GANN"+i)< RefVWAP, i, sBelowI);
bAboveI = sBelowI + 1;
sBelow = VarGet("GANN"+sBelowI);
bAbove = VarGet("GANN"+bAboveI);
}




BuySignal = H > bAbove AND TimeNum() > 092900;
ShortSignal = L < sBelow AND TimeNum() > 092900;

BuySignal = ExRem(BuySignal,ShortSignal);
ShortSignal = ExRem(ShortSignal,BuySignal);

BuyProfitStop = H > (0.995 * VarGet("Gann"+(bAboveI+1)));
ShortProfitStop = L < (1.005 * VarGet("Gann"+(sBelowI-1)));

SetOption("MaxOpenPositions", 1 );
SetPositionSize(100,spsShares);

Buy = BuySignal;
Sell = ShortSignal OR BuyProfitStop;
Short = ShortSignal;
Cover = BuySignal OR ShortProfitStop;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

ByStat = Flip(Buy,Sell);
ShStat = Flip(Short,Cover);

// Resistance Levels (or Targets for Buy trade)
BTgt1 = 0.9995 * VarGet("Gann"+(bAboveI+1));
BTgt2 = 0.9995 * VarGet("Gann"+(bAboveI+2));
BTgt3 = 0.9995 * VarGet("Gann"+(bAboveI+3));

// Support Levels (or Targets for Short trade)
STgt1 = 1.0005 * VarGet("Gann"+(sBelowI-1));
STgt2 = 1.0005 * VarGet("Gann"+(sBelowI-2));
STgt3 = 1.0005 * VarGet("Gann"+(sBelowI-3));


GfxSetBkMode( 1 );
GfxSelectFont("Courier New", 9, 700 );
GfxSetTextColor( colorRed );
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorWhite );


BTgtext = "Buy Targets : " + NumToStr(btgt1,1.2,False) + " - " + NumToStr(btgt2,1.2,False) + " - " + NumToStr(btgt3,1.2,False);
STgtext = "Short Targets : " + NumToStr(stgt1,1.2,False) + " - " + NumToStr(stgt2,1.2) + " - " + NumToStr(stgt3,1.2,False);

GfxTextOut("Current time : " + TimeNum(), 625, 25);

GfxTextOut("Buy Above : " + WriteIf(TimeNum()>092900, NumToStr(bAbove,1.2,False) + " SL : " + NumToStr(sBelow,1.2,False),"Waiting for Signal"), 625, 45);
GfxTextOut(WriteIf(TimeNum()>092900,BTgtext,""), 625, 55);

GfxTextOut("Short Below : " + WriteIf(TimeNum()>092900, NumToStr(sBelow,1.2,False) + " SL : " + NumToStr(bAbove,1.2,False),"Waiting for Signal"), 625, 75);
GfxTextOut(WriteIf(TimeNum()>092900,STgtext,""), 625, 85);

_SECTION_END();




PlotOHLC( babove, sbelow, babove,sbelow, "", ColorRGB(255,255,128), styleCloud);
PlotOHLC( sbelow, babove, sbelow,babove, "", colorYellow, styleCloud); SetChartOptions(0,chartShowArrows|chartShowDates);





Plot(BTgt1,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt2,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt3,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);


Plot(STgt1,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt2,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt3,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
 
#17
Nothing much changed in the origional AFL, I lost the origional but below is almost same. I modified only buy sell and profit booking conditions


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates,colorRed);


Plot(C,"Price",IIf(C>O,colorBrightGreen,colorBrown),styleCandle);






_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", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();

_SECTION_BEGIN("GaNN Square of Nine");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

TodayVolume = Sum(V,BarsToday);

VWAP = (Sum (((C+O+H+L)/4) * V, BarsToday ) / TodayVolume);




RefVWAP = ValueWhen(TimeNum() == 092900, C,1);

Plot (VWAP,"VWAP",colorBlue, styleStaircase = 512 );




BaseNum = (int(sqrt(RefVWAP))-1);
sBelow = BaseNum + BaseNum;
sBelowI = 1;

//Calculate levels for GANN Square of Nine

for( i = 1; i < 50; i++ )
{
VarSet( "GANN"+i, (BaseNum * BaseNum) );
BaseNum = BaseNum + 0.125;
sBelowI = IIf( VarGet("GANN"+i)< RefVWAP, i, sBelowI);
bAboveI = sBelowI + 1;
sBelow = VarGet("GANN"+sBelowI);
bAbove = VarGet("GANN"+bAboveI);
}




BuySignal = H > bAbove AND TimeNum() > 092900;
ShortSignal = L < sBelow AND TimeNum() > 092900;

BuySignal = ExRem(BuySignal,ShortSignal);
ShortSignal = ExRem(ShortSignal,BuySignal);

BuyProfitStop = H > (0.995 * VarGet("Gann"+(bAboveI+1)));
ShortProfitStop = L < (1.005 * VarGet("Gann"+(sBelowI-1)));

SetOption("MaxOpenPositions", 1 );
SetPositionSize(100,spsShares);

Buy = BuySignal;
Sell = ShortSignal OR BuyProfitStop;
Short = ShortSignal;
Cover = BuySignal OR ShortProfitStop;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

ByStat = Flip(Buy,Sell);
ShStat = Flip(Short,Cover);

// Resistance Levels (or Targets for Buy trade)
BTgt1 = 0.9995 * VarGet("Gann"+(bAboveI+1));
BTgt2 = 0.9995 * VarGet("Gann"+(bAboveI+2));
BTgt3 = 0.9995 * VarGet("Gann"+(bAboveI+3));

// Support Levels (or Targets for Short trade)
STgt1 = 1.0005 * VarGet("Gann"+(sBelowI-1));
STgt2 = 1.0005 * VarGet("Gann"+(sBelowI-2));
STgt3 = 1.0005 * VarGet("Gann"+(sBelowI-3));


GfxSetBkMode( 1 );
GfxSelectFont("Courier New", 9, 700 );
GfxSetTextColor( colorRed );
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorWhite );


BTgtext = "Buy Targets : " + NumToStr(btgt1,1.2,False) + " - " + NumToStr(btgt2,1.2,False) + " - " + NumToStr(btgt3,1.2,False);
STgtext = "Short Targets : " + NumToStr(stgt1,1.2,False) + " - " + NumToStr(stgt2,1.2) + " - " + NumToStr(stgt3,1.2,False);

GfxTextOut("Current time : " + TimeNum(), 625, 25);

GfxTextOut("Buy Above : " + WriteIf(TimeNum()>092900, NumToStr(bAbove,1.2,False) + " SL : " + NumToStr(sBelow,1.2,False),"Waiting for Signal"), 625, 45);
GfxTextOut(WriteIf(TimeNum()>092900,BTgtext,""), 625, 55);

GfxTextOut("Short Below : " + WriteIf(TimeNum()>092900, NumToStr(sBelow,1.2,False) + " SL : " + NumToStr(bAbove,1.2,False),"Waiting for Signal"), 625, 75);
GfxTextOut(WriteIf(TimeNum()>092900,STgtext,""), 625, 85);

_SECTION_END();




PlotOHLC( babove, sbelow, babove,sbelow, "", ColorRGB(255,255,128), styleCloud);
PlotOHLC( sbelow, babove, sbelow,babove, "", colorYellow, styleCloud); SetChartOptions(0,chartShowArrows|chartShowDates);





Plot(BTgt1,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt2,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);
Plot(BTgt3,"",colorGreen,styleStaircase|styleSwingDots|styleNoRescale);


Plot(STgt1,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt2,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
Plot(STgt3,"",colorRed,styleStaircase|styleSwingDots|styleNoRescale);
The tgt and buy,sell price does not show on 5 min and 15 min TF only on 1 Min tf
 

Similar threads