Join our facebook group for Amibroker afl code discussion https://www.facebook.com/groups/603980776889348

Multiple MA Perfect Crossover Buy Sell System

Multiple MA Perfect Crossover Buy Sell System
Multiple MA Perfect Crossover Buy Sell System

//www.aflcode.com
SetChartBkColor(  ColorHSB( 42, 42, 62 ) ); 
SetChartOptions(0,chartShowArrows|chartShowDates); 
Plot( C, "Close",  47 , styleNoTitle | styleCandle ); 

function T3(price,periods)
{
s = 0.84;
e1=EMA(price,periods);
e2=EMA(e1,Periods);
e3=EMA(e2,Periods);
e4=EMA(e3,Periods);
e5=EMA(e4,Periods);
e6=EMA(e5,Periods);
c1=-s*s*s;
c2=3*s*s+3*s*s*s;
c3=-6*s*s-3*s-3*s*s*s;
c4=1+3*s+s*s*s+3*s*s;
Ti3=c1*e6+c2*e5+c3*e4+c4*e3;
return ti3;
}
Type1 = ParamList("Type 1", "Simple,Exponential,Double Exponential,Tripple Exponential,Wilders,Weighted,T3",0);
prd=Param("periods type1",5,3,100,1);
m = 0;
if( Type1 == "Simple" )     m = MA( C, Prd );
if( Type1 == "Exponential" )    m = EMA( C, Prd );
if( Type1 == "Double Exponential" )  m = DEMA( C, Prd );
if( Type1 == "Tripple Exponential" )  m = TEMA( C, Prd );
if( Type1 == "Wilders" )     m = Wilders( C, Prd );
if( Type1 == "Weighted" )     m = WMA( C, Prd );
if( Type1 == "T3" )            m = T3(C,Prd);

Type2 = ParamList("Type 2", "Simple,Exponential,Double Exponential,Tripple Exponential,Wilders,Weighted",5);
m1 = 0;
prd1=Param("periods type2",20,5,200,1);
if( Type2 == "Simple" )     m1 = MA( C, Prd1 );
if( Type2 == "Exponential" )    m1 = EMA( C, Prd1 );
if( Type2 == "Double Exponential" )  m1 = DEMA( C, Prd1 );
if( Type2 == "Tripple Exponential" )  m1 = TEMA( C, Prd1 );
if( Type2 == "Wilders" )     m1 = Wilders( C, Prd1 );
if( Type2 == "Weighted" )     m1 = WMA( C, Prd1 );
Plot(m,  "", colorSkyblue, 1);
Plot(m1, "",IIf(m1>Ref(m1,-1),5,4), 4);

Buysetup=Cross(m,m1) ;
Shortsetup=Cross(m1,m) ;
Buysetupvalid=Flip (Buysetup, Shortsetup);
Shortsetupvalid=Flip (Shortsetup, Buysetup);

Buy=Cover= Buysetupvalid;
Sell=Short= Shortsetupvalid;


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

BuyPrice=SellPrice=ShortPrice=CoverPrice=C;

GraphXSpace = 5;
dist = 1.5*ATR(10); 
for( i = 0; i < BarCount; i++ ) 
{ if( Buy[i] ) PlotText( "+\n@" + BuyPrice[ i ], i, L[ i ]-dist[i], colorBrightGreen ); 
  if( Short[i] ) PlotText( "-ht\n@" + ShortPrice[ i ], i, H[ i ]+dist[i], colorRed);
  if( Cover[i] ) PlotText( "Cver\n@" + CoverPrice[ i ], i, L[ i ]-dist[i], colorLime ); 
  if( Sell[i] ) PlotText( "Sl\n@" + SellPrice[ i ], i, H[ i ]+dist[i], colorOrange); }
PlotShapes (IIf (Sell,shapeHollowSmallDownTriangle, shapeNone), colorOrange, 0, H, - 15); 
PlotShapes (IIf (Cover,shapeHollowSmallUpTriangle, shapeNone), colorGreen, 0, L, - 15);
PlotShapes (IIf (Buy,shapeUpArrow, shapeNone), colorBrightGreen, 0, L, - 25);
PlotShapes (IIf (Short,shapeDownArrow, shapeNone), colorRed, 0, H, - 25); 
Filter=Buy OR Sell OR Short OR Cover ;
AddColumn(IIf(Buy,BuyPrice,Null),"Buy/cover", 6.2,1,colorGreen);
AddColumn(IIf(Sell,SellPrice,Null),"sell /short" ,6.2,1,colorOrange);
AddColumn(IIf(Short,ShortPrice,Null),"short Price", 6.2,1,colorRed);
AddColumn(IIf(Cover,CoverPrice,Null),"cover Price", 6.2,1,colorLime);


Title = "{{NAME}} - {{INTERVAL}} - {{DATE}}  : {{OHLCX}} " +EncodeColor(colorAqua)+
"\n"+"Multi MA cross system"+
"\n\n"+EncodeColor(colorSkyblue)+WriteIf(m,"("+type1+"--"+prd+")  "+WriteVal(m)+",","")+
"\n"+EncodeColor(7)+WriteIf(m1,"("+type2+"--"+prd1+")  "+WriteVal(m1)+" ,","")+ " "+
"\n"+EncodeColor(colorPink)+WriteIf(C-M,"disance from  "+type1+" ma "+WriteVal(C-M)+",","");


//Plot(V, "", colorPaleBlue, 2|styleOwnScale); 

_SECTION_BEGIN("Background text");
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/6 );
GfxSetTextAlign( 6 );// center alignment
//GfxSetTextColor( ColorRGB( 200, 200, 200 ) );
GfxSetTextColor( ColorHSB( 42, 42, 82 ) );
GfxSetBkMode(0); // transparent
//GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/12 );
GfxSelectFont("Tahoma", Status("pxheight")/12 );
//GfxTextOut( "Multi MA cross system", Status("pxwidth")/2, Status("pxheight")/3 );
GfxSelectFont("Tahoma", Status("pxheight")/36 );
//GfxTextOut( "Chart by Cas", Status("pxwidth")/2, Status("pxheight")/2 );
_SECTION_END();
Previous
Next Post »