Home » AFL Code, Amibroker

Simple AFL code for 5 EMA(High-Low)

27 December 2009 1,206 views 14 Comments

Here the Idea is to design a basic 5 EMA(High-Low) system which could produce
Buy/Sell Signals whenever the candle crosses the 5 EMA(High/Low) lines
i.e A Buy Signal should produced when it crosses and closes above 5 EMA(High) line
and a Sell Signal should produced when it crosses and closes below 5 EMA(low) line

Buy =  Cross(Close,EMA(High,5));
Sell = Cross(EMA(Low,5),Close);

Amibroker’s AFL code had been designed to implement this system with Green Arrows in
the charts indicating Buy Signal and the Red downward arrows indicating sell signal
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);

Both the weekly and Daily charts are shown with buy/sell signals. Just like any other trend following
system 5 EMA(High-Low) also works bad when the trend is side ways and produce more mixed signals
And where there is a strong trend the signals are good and could generate good potential returns.
The Complete AFL code for 5 EMA(High-Low) Buy/Sell Trading system

_SECTION_BEGIN(“5 EMA High-Low”);
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( Close, “Close”, ParamColor(“Color”, colorBlack ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );
Buy = Cross(Close,EMA( High , 5 ));
Sell = Cross(EMA( Low , 5 ),Close);
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);
Plot( EMA( Low,5), “5 EMA LOW”,ParamColor(“Color”, colorBlue ),styleNoRescale);
Plot( EMA( High,5), “5 EMA High”,ParamColor(“Color”, colorBlue ),styleNoRescale);
_SECTION_END();

Related Readings and Observations

  • 52 Week High and Low Stock Scanner – AFL Code
    Here is a simple afl code which scans for 52 week High and Low from the list of available EOD stocks database and list them in Amibroker Software...
  • Start Scanning Stocks using Amibroker Exploration
    Now all you need to do is you have to find the list of stocks that had recently made 5/20 EMA crossover from the bunch of NSE Stock pack and also you have to scan the stocks with price value greater than Rs50. And also print the values of 5EMA and 2...
  • GANN Level Plotter for Nifty
    GANN Level Plotter INDICATOR PLOTS FOR ANY STOCK AND WORKS FINE FOR LIQUID CONTRACTS AND STOCKS. THE LEVELS ARE NOT FOR TRADING, BUT FOR REFERENCE SO THAT ENTRY AND EXIT WILL BE SMOOTH....
  • Profit Table – Amibroker AFL Code
    Here is an another interesting afl code which plots the Profit table for any sort of Instruments in Amibroker. Month-on-Month , Year-on-Year, Average monthly returns in terms of percentage can be plotted using this afl code. Sample AFL code for Nift...
  • 70/1030 EMA AFL code for Amibroker
    Here is a simple logic how to plot 70min/ 1030min EMA in your amiboker software. 70/1030 EMA crossover is a popular strategy witht the yahoo 5min charts. And if your tried with amibroker with the same 70min and 1030 min you would probably end with th...

Written by: Rajandran R

diggdelicious-buttonstumbleuponTechnoratiFacebookNewsvineRedditYahoo
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading ... Loading ...

14 Comments »

  • Market Hypothesis said:

    Little modification is required. Please draw the 5EMA (High Low) Band.

  • Rajandran said:

    I had added in the coding part alone

  • Market Hypothesis said:

    Dear RajI have just modified your afl i.e.Buy = Cross(Close,EMA( Low , 5 ));Sell = Cross(EMA( High , 5 ),Close);and found more meaningful. Please do comment on this modification.

  • Rajandran said:

    Its adds more value to the trading systemin minimizing the losses and producing avalueable system.

  • Market Hypothesis said:

    One more modification is required. Just open daily Nifty Chart and just watch 16-12-2009. it has given false signal. I do not know how to omit it but this type of false signal can be omitted.If possible then it will be great trading system.Thanks

  • Rajandran said:

    Iam sorry iam not getting any false signal on 16-12-2009

  • Market Hypothesis said:

    More modification done in Buy sell.Buy = Cross(Close,EMA( Low , 5 ))OR Cross(Close,EMA( High , 5 )); Sell = Cross(EMA( High , 5 ),Close)OR Cross(EMA( Low , 5 ),Close);It works fine in hourly and daily chart. I have added your earlier Buy Sell signal conditionally because if turn around happened within the band then this conditional extension is required.

  • Rajandran said:

    @ShyamWe should not try to create more buy/sell signals.As this would create a mess. The scope of creating a buy/sell signal is to identify turns earlier and to generate potential profits. If you include 5 EMA signals also then it would probably create a mess and finally ends in confusion(i.e should we have to believe this signal or not)

  • Rajandran said:

    if the signal density is high then your profit potential is very low

  • dinesh said:

    hi thanks for afl. pls explain how to trade with help of this afl. on which scripts gives good results?

  • Rajandran R said:

    Dinesh,
    I tried for hourly, Daily and Weekly yielding good results. to know how to trade this afl just visit this post Simple Rules to Trade Using 5 EMA(LOW-HIGH)

  • dipak said:

    Sir,

    This code is not working. Giving the error at 1st & Last line. Error 31. Syntax error, expecting ‘)’ or’,’

    Regards,

    Dipak

  • Rajandran R said:

    Dipak,
    It works fine for me. Its all the basic codings. So it should work in all versions of amibroker too

  • Aliasgar said:

    Hello Rajendran,

    Please paste again full AFL with modification suggested by above members.

    Or I should use below code.

    =======================================================================
    _SECTION_BEGIN(“5 EMA High-Low”);
    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( Close, “Close”, ParamColor(“Color”, colorBlack ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );

    Buy = Cross(Close,EMA( Low , 5 ));
    Sell = Cross(EMA( High , 5 ),Close);

    PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
    PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);
    Plot( EMA( Low,5), “5 EMA LOW”,ParamColor(“Color”, colorBlue ),styleNoRescale);
    Plot( EMA( High,5), “5 EMA High”,ParamColor(“Color”, colorBlue ),styleNoRescale);
    _SECTION_END();
    =======================================================================

    Thanks,
    Aliasgar

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

Optionally add an image (JPEG only)