_SECTION_BEGIN("Price");//setting =0.085 stock LT-or 0.057 nifty 0.10
//FOR NIFTY 0.444 IS OK
//for High value commodities like Gold & silver…order need to be 0.5 for better result.
//FOR STOCKS 0.1 IS OK // i tried 0.1 it is ok
SetChartBkColor(64);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
//http://www.wisestocktrader.com/indicators/2747-gann-levels-with-tgt-sl.txt
//Just paste thsi code at the end of your exisiting AFL & you get a perfect Breakout system to use
//You are right just paste on price chart AND it will work.
_SECTION_BEGIN("GANN Levels");
/*
For Stocks/Index/Commodities "order" need to be 0.1 to 0.5
For Forex "order" should be 0.001 ( except JPY pairs ), for JPY pairs it need to be 0.01
*/
Op=TimeFrameGetPrice("O",inDaily,0);
//order=Param("Order",0.5,0.001,0.1,0.001,sincr = 0);
order=Param("Order",0.1,0.001,0.5,0.001,sincr = 0);//0.10 IS OK
level1 = 1.25;
level2 = 2.50;
level3 = 3.33;
level4 = 5;
level5 = 6.66;
level6 = 7.5;
level7 = 10;
level1 = level1 * order;
level2 = level2 * order;
level3 = level3 * order;
level4 = level4 * order;
level5 = level5 * order;
level6 = level6 * order;
level7 = level7 * order;
bAboveI=(sqrt(Op)+level1)*(sqrt(Op)+level1); // BUY Zone
bAbove = round(bAboveI);
sBelowI=(sqrt(Op)-level1)*(sqrt(Op)-level1); // SELL Zone
sBelow = round(sBelowI);
Sstop= bAbove ;
Bstop= sBelow ;
// Resistance Levels (or Targets for Buy trade)
BTgt1 = round((sqrt(Op)+level2)*(sqrt(Op)+level2));
BTgt2 = round((sqrt(Op)+level3)*(sqrt(Op)+level3));
BTgt3 = round((sqrt(Op)+level4)*(sqrt(Op)+level4));
BTgt4 = round((sqrt(Op)+level5)*(sqrt(Op)+level5));
BTgt5 = round((sqrt(Op)+level6)*(sqrt(Op)+level6));
BTgt6 = round((sqrt(Op)+level7)*(sqrt(Op)+level7));
// Support Levels (or Targets for Short trade)
STgt1 = round((sqrt(Op)-level2)*(sqrt(Op)-level2));
STgt2 = round((sqrt(Op)-level3)*(sqrt(Op)-level3));
STgt3 = round((sqrt(Op)-level4)*(sqrt(Op)-level4));
STgt4 = round((sqrt(Op)-level5)*(sqrt(Op)-level5));
STgt5 = round((sqrt(Op)-level6)*(sqrt(Op)-level6));
STgt6 = round((sqrt(Op)-level7)*(sqrt(Op)-level7));
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)+ " - " + NumToStr(btgt4,1.2,False) + " - " + NumToStr(btgt5,1.2,False) + " - " + NumToStr(btgt6,1.2,False);
STgtext = "Short Targets : " + NumToStr(stgt1,1.2,False) + " - " + NumToStr(stgt2,1.2,False) + " - " + NumToStr(stgt3,1.2,False)+ " - " + NumToStr(stgt4,1.2,False) + " - " + NumToStr(stgt5,1.2,False) + " - " + NumToStr(stgt6,1.2,False);
// GANN levels based on MKT opening price ( please change this time according to exchnage opening time )
GfxTextOut("Buy Above : " + WriteIf(TimeNum()>092900, NumToStr(bAbove,1.2,False) + " SL : " + NumToStr(sBelow,1.2,False),"Waiting for Signal"), 10, 65);
GfxTextOut(WriteIf(TimeNum()>092900,BTgtext,""), 10, 85);
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, 105);
GfxTextOut(WriteIf(TimeNum()>092900,STgtext,""), 10, 125);
BuySignal = (Cross(H,babove)OR Cross(C,babove) OR (H>babove AND L<=babove)) AND Op<babove ;
ShortSignal = (Cross(Sbelow,L) OR Cross(Sbelow,C) OR (H>=sbelow AND L<sbelow))AND Op>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;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ShortSignal;
Cover = C>SStop OR ShortProfitStop;
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);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );
PlotShapes(IIf(Cover, shapeUpArrow,shapeNone),colorGreen, 0, Low, Offset=-20);
PlotShapes(IIf(Sell, shapeDownArrow,shapeNone),colorRed, 0, High, Offset=-20);
numbars = LastValue(Cum(Status("barvisible")));
hts = -33.5;
gl = ParamToggle("GANN Levels","Show|Hide",0);
if(gl==1) {
Plot(sstop,"BUY Zone",colorDarkGreen,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(bstop,"SELL Zone",colorDarkRed,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(BTgt1,"BUY TGT1",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(BTgt2,"BUY TGT2",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(BTgt3,"BUY TGT3",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(BTgt4,"BUY TGT4",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(BTgt5,"BUY TGT5",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(BTgt6,"BUY TGT6",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );
Plot(STgt1,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(STgt2,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(STgt3,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(STgt4,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(STgt5,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(STgt6,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText(" BUY Zone" , LastValue(BarIndex())-(numbars/Hts), LastValue(sstop,1), colorDarkGreen);
PlotText(" SELL Zone" , LastValue(BarIndex())-(numbars/Hts), LastValue(bstop,1), colorDarkRed);
PlotText(" BUY TGT1" , LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt1,1), colorOrange);
PlotText(" BUY TGT2" , LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt2,1), colorOrange);
PlotText(" BUY TGT3" , LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt3,1), colorOrange);
PlotText(" BUY TGT4" , LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt4,1), colorOrange);
PlotText(" BUY TGT5" , LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt5,1), colorOrange);
PlotText(" BUY TGT6" , LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt6,1), colorOrange);
PlotText(" SELL TGT1" , LastValue(BarIndex())-(numbars/Hts), LastValue(STgt1,1), colorLime);
PlotText(" SELL TGT2" , LastValue(BarIndex())-(numbars/Hts), LastValue(STgt2,1), colorLime);
PlotText(" SELL TGT3" , LastValue(BarIndex())-(numbars/Hts), LastValue(STgt3,1), colorLime);
PlotText(" SELL TGT4" , LastValue(BarIndex())-(numbars/Hts), LastValue(STgt4,1), colorLime);
PlotText(" SELL TGT5" , LastValue(BarIndex())-(numbars/Hts), LastValue(STgt5,1), colorLime);
PlotText(" SELL TGT6" , LastValue(BarIndex())-(numbars/Hts), LastValue(STgt6,1), colorLime);
}
_SECTION_END();
//============ADD MAMA FAMA AFL HERE
_SECTION_BEGIN("MAMA");
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorRed,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
//===========================================
_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorGreen) );
Hor=Param("Horizontal Position",1050,1,1200,1);
Ver=Param("Vertical Position",1,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorGreen) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );
_SECTION_END();
SetChartBkColor(64);
SetBarsRequired( 10000, 10000 );
SetChartOptions(0,chartShowArrows|chartShowDates);
prc = ( High + Low ) / 2;
fastlimit = 0.5;
slowlimit = 0.05;
pi=4*atan(1);
RTD=180/pi;
DTR=pi/180;
Cyclepart=Optimize("Alpha",Param ("Alpha",0.8,0.1,1,0.1),0.1,1,0.1);
Smooth[0] = Period = Detrender[0] = I1[0] = Q1[0] = 0;
phase[0]=deltaphase[0]=MAMA[0]=FAMA[0]=0;
for ( i = 6; i < BarCount; i++ )
{
Smooth[i] = ( 4 * prc[i] + 3 * prc[i-1] + 2 * prc[i-2] + prc[i-3] ) / 10;
AmpCorr[i] = 0.075 * Period[i-1] + 0.54;
Detrender[i] = ( 0.0962 * Smooth[i] + 0.5769 * Smooth[i-2] - 0.5769 * Smooth[i-4] - 0.0962 * Smooth[i-6] ) * AmpCorr[i];
Q1[i] = ( 0.0962 * Detrender[i] + 0.5769 * Detrender[i-2] - 0.5769 * Detrender[i-4] - 0.0962 * Detrender[i-6] ) * AmpCorr[i];
I1[i] = Detrender[i-3];
if (I1[i] != 0) phase[i] = DTR*360/atan(q1[i]/I1[i]);
deltaphase[i]=phase[i-1]-phase[i];
if (deltaphase[i] <1) deltaphase[i]=1;
alpha[i]=fastlimit[i]/deltaphase[i];
if (alpha[i] < slowlimit[i]) alpha[i]=slowlimit[i];
MAMA[i]=alpha[i] * prc [i] +(1-alpha[i])*MAMA[i-1];
FAMA[i]=Cyclepart*alpha[i] * prc [i] +(1-Cyclepart*alpha[i])*FAMA[i-1];
}
Plot( MAMA, "MAMA", colorTurquoise, styleLine|styleThick );
Plot( FAMA, "FAMA", colorYellow, styleLine|styleThick );
PlotOHLC(O,H,L,C,"MAMA",IIf(MAma>fama,colorLime,colorRed),styleCandle|styleThick);
_SECTION_END();
_SECTION_BEGIN("SYSTEM");
BuySetupValue=ValueWhen(Cross(MAMA,FAMA),H,1);
shortsetupValue=ValueWhen(Cross(FAMA,MAMA),L,1);
Buysetup =Cross(MAMA,FAMA) ;
shortsetup = Cross(FAMA,MAMA);
Longa = Flip(Buysetup,shortsetup);
shrta = Flip(shortsetup,Buysetup);
Buy=Longa AND Cross(C,BuySetupValue);
Short=shrta AND Cross(shortsetupValue,C);
Buy = ExRem(Buy,Short);
Short = ExRem(Short,Buy);
Sell = Short;
Cover = Buy;
t1= Flip(Buy,Short);
t2= Flip(Short,Buy);
BPrice=ValueWhen(t1 AND Ref(t1,-1)==0,C,1);
SPrice=ValueWhen(t2 AND Ref(t2,-1)==0,C,1);
GraphXSpace = 5;
dist = 1.5*ATR(20);
Signalpt = ValueWhen(Buy OR Short,C);
profittgt = Signalpt * 0.006;
Buytgt = Signalpt + profittgt; Buytgt = Prec(Buytgt ,2);
Shorttgt = Signalpt - profittgt;Shorttgt = Prec ( Shorttgt,2);
/*for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "" + C[ i ], i, L[ i ]-dist[i], colorLime );
if( Short[i] ) PlotText( "" + C[ i ], i, H[ i ]+dist[i], colorYellow );
}*/
_SECTION_END();
//=================TITLE============================ ================================================== ==================
_SECTION_BEGIN("Title");
//===============================================NEW PERIOD============================================ ====
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;
//if ( NewPeriod ){Say( "New period" );Plot( 1, "", colorYellow, styleArea | styleOwnScale, 0, 1 );}
//===============================================END NEW PERIOD============================================ ==============
if( Status("action") == actionIndicator )
/*
(
Title = EncodeColor(colorWhite)+ "MAMA TRADING SYSTEM" + EncodeColor(colorYellow) +" Open-"+O+" "+"High-"+H+" "+"Low-"+L+" "+
"Close-"+C+" "+ "Vol= "+ WriteVal(V)+EncodeColor(colorLime)+"\n"+" BUY SETUP - "+WriteVal(BuySetupValue)+EncodeColor(colorRed )
+" SELL SETUP - "+WriteVal(shortsetupValue)+"\n"+ EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+EncodeColor(colorRed)+
WriteIf (Short , " GO SHORT / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Short , "Total Profit/Loss for the Last Trade Rs."+Prec(C-BPrice,2)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+Prec(SPrice-C,2)+"","")+
WriteIf(t1 AND NOT Buy, "Trade : Long - Entry price Rs."+(BPrice),"")+
WriteIf(t2 AND NOT Short, "Trade : Short - Entry price Rs."+(SPrice),"")+"\n"+
WriteIf(t1 AND NOT Buy, "Current Profit/Loss Rs."+Prec(C-BPrice,2)+"","")+
WriteIf(t2 AND NOT Short, "Current Profit/Loss Rs."+Prec(SPrice-C,2)+"","")+"\n"+EncodeColor(colorYellow)+" Current Time: " + Now( 2 )
+"\n"+EncodeColor(colorLime)+ WriteIf(t1 AND NOT Buy,"First Target : "+Buytgt+","+EncodeColor(colorRed)+" ADD @ "+Shorttgt+"","")+
EncodeColor(colorRed)+WriteIf(t2 AND NOT Short,"First Target : "+Shorttgt+","+EncodeColor(colorGreen)+" ADD @ "+Buytgt+"","")
);
*/
PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorGreen, 0, L, Offset=-10);
PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorGreen, 0,L, Offset=-15);
PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorGreen, 0,L, Offset=-20);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);
PlotShapes(IIf(Short, shapeCircle, shapeNone),colorRed, 0, H, Offset=10);
PlotShapes(IIf(Short, shapeCircle, shapeNone),colorRed, 0,H, Offset=15);
PlotShapes(IIf(Short, shapeCircle, shapeNone),colorRed, 0,H, Offset=20);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-15);
WriteVal(BuyPrice);
WriteVal(Longa);
WriteVal(t1);
WriteVal(ShortPrice);
WriteVal(shrta);
_SECTION_END();