Wednesday, June 11, 2014

Learn AFL Code: EMA cross over system part 2

This is our second post for EMA cross using AFL. In our first post we learned to design our logic for ema cross over. Now as you have already learned how to draw price action and how to generate signal. Now you want to plot your favorite EMA in chart. how can you do it?

_SECTION_BEGIN("EMA 20/50 cross over system");

//Showing price on chart
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( Close, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

//Buy logic
Buy= Cross(EMA( C, 20 ), EMA( C, 50 ));
//Sell logic
Sell= Cross(EMA( C, 50 ), EMA( C, 20 ));

//Plot EMA in AFL chart
Plot( EMA( C,20), "20 EMA Close",ParamColor("EMA 20 Color", colorGreen ),styleNoRescale);
Plot( EMA( C,50), "50 EMA Close",ParamColor("EMA 50 Color", colorRed ),styleNoRescale); 

_SECTION_END();


Now you change your EMA parameters and implement your logic.
You can use more than two EMA also in AFL. Like

Plot( EMA( C,10), "10 EMA Close",ParamColor("EMA 10 Color", colorGreen ),styleNoRescale);
Plot( EMA( C,20), "20 EMA Close",ParamColor("EMA 20 Color", colorRed ),styleNoRescale);
Plot( EMA( C,30), "30 EMA Close",ParamColor("EMA 30 Color", colorGreen ),styleNoRescale);
Plot( EMA( C,40), "40 EMA Close",ParamColor("EMA 40 Color", colorRed ),styleNoRescale);

As many as you want. Goto part three for complete signal based chart.


Debarghya Mukherjee
Mobile: (+91)-9038787021
Email: debarghya_mkr@yahoo.com






No comments:

Post a Comment