Friday, October 11, 2024

AFL CODE-COLOR MACD (BUY SELL SIGNALS)

_SECTION_BEGIN("MACD");

r1 = Param( "Fast avg", 12, 2, 200, 1 );

r2 = Param( "Slow avg", 26, 2, 200, 1 );

r3 = Param( "Signal avg", 9, 2, 200, 1 );

Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), 

IIf(MACD(r1,r2)<Signal(r1,r2,r3), IIf(MACD(r1,r2)>0,colorPink,colorRed),IIf(MACD(r1,r2)<0,colorTurquoise,colorGreen)) , ParamStyle("MACD style", styleThick) );

Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorDarkBlue ), ParamStyle("Signal style", styleThick) );

Plot( ml-sl, "MACD Histogram", IIf(ml>sl,IIf(ml>0,colorLime,colorBlue),IIf(ml<0,colorDarkRed,colorPink)), ParamStyle("Histogram style", styleHistogram | styleNoLabel, maskHistogram ) );

Line1= LineArray (0,0,LastValue(BarIndex()),0,20);

Plot (Line1,"Zero line", colorLightGrey, styleDashed | styleNoTitle);


//_SECTION_END();

//_SECTION_BEGIN("Buy-Sell Signals");

trend1 = Max(MA(Close,r1),MA(Close,r2));

trend2 = Min(MA(Close,r1),MA(Close,r2));

Crossup = Cross(MACD(r1,r2),Signal(r1,r2,r3));

Crossdn = Cross(Signal(r1,r2,r3), MACD(r1,r2));

Sell1 = Close >= trend2 AND Crossdn;

Sell2 = Close <= trend2 AND Crossdn;

Buy1 = Close <= trend2 AND Crossup;

Buy2 = Close >= trend1 AND Crossup;

PlotShapes(IIf(Buy1, shapesmallUpTriangle, IIf(Buy2,shapeUpArrow, shapeNone)), colorBlue);

PlotShapes(IIf(Sell1, shapesmalldownTriangle, IIf(Sell2,shapeDownArrow, shapeNone)), colorRed);

_SECTION_END();


👉Tải tại đây

https://drive.google.com/file/d/1dzQjlCoKJn42SasFGZn9aeYtU5XTOtKs/view?usp=drive_link

Cách sử dụng AFL  cho Amibroker  

Tải xuống tệp Amibroker AFL. 

Bây giờ hãy sao chép tệp afl và dán vào vị trí cài Amibroker  

D:\A KY PC\Win\Amibroker\Formulas\VIP free


1 comment: