Showing posts with label EMA cross over. Show all posts
Showing posts with label EMA cross over. Show all posts

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






Learn AFL code : EMA cross over system part 1

In our last post we learned about basic structure of AFL coding, and I said that, you can make your own buy and sell signal logic and can use it. So lets make some sample buy and sell signal.
I am taking a very simple trading logic, that is "EMA cross over system". We all know that is any "EMA cross over system we a higher time frame EMA and one smaller. Once the smaller EMA crosee higher a buy signal is generated and revrse is true from sell signal.

May be you have EMA/MA cross over system that uses EMA20 and EMA50. I am writing the code for it,


Buy= Cross(EMA( C, 20 ), EMA( C, 50 ));

Sell= Cross(EMA( C, 50 ), EMA( C, 20 ));

Now here replace 20 and 50 with your desired value. This will generate nice signal for your 20/50 EMA cross over system. Go long when EMA(20) crosses EMA(50). and sell in opposite. Go to part two for complete chart.

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