Code Moving Average for Amibroker (AFL) | Đường trung bình cho Amibroker (AFL)
Amibroker AFL cho giao dịch trung bình di chuyển với tín hiệu mua
_SECTION_BEGIN("Price");
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("MA_CROSS");
p = Optimize("PERIOD 1",Param("PERIOD 1",10,2,30,1),2,20,2);
q = Optimize("PERIOD 2",Param("PERIOD 2",90,10,200,10),10,100,10);
y = Optimize("MAType 1",Param("MAType 1",2,1,8,1),1,8,1);
z = Optimize("MAType 2",Param("MAType 2",2,1,8,1),1,8,1);
m=0; if (y==1) m = MA(C,p);
else if (y==2) m = EMA(C,p);
else if (y==3) m = DEMA(C,p);
else if (y==4) m = TEMA(C,p);
else if (y==5) m = WMA(C,p);
else if (y==6) m = HMA(C,p);
else if (y==7) m = Wilders(C,p);
else if (y==8) m = LinearReg(C,p);
n=0; if (z==1) n = MA(C,q);
else if (z==2) n = EMA(C,q);
else if (z==3) n = DEMA(C,q);
else if (z==4) n = TEMA(C,q);
else if (z==5) n = WMA(C,q);
else if (z==6) n = HMA(C,q);
else if (z==7) n = Wilders(C,q);
else if (z==8) n = LinearReg(C,q);
Plot(m," MA",IIf(m < Ref(m,-1),colorBlue,colorRed),styleThick);
Plot(n," MA",IIf(n < Ref(n,-1),colorBlue,colorRed),styleThick);
Buy = Cross(m,n);
Sell = Cross(n,m);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = Sell; Cover = Buy;
PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H));
SetPositionSize(1,4);
_SECTION_END();
Comments
Post a Comment