Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Simple AFL code for 5 EMA(High-Low)

56 sec read


 

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();

Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Algomojo Index Straddle/Strangle Execution Module with Intraday Stoploss

This tutorial focus on how to automate your index straddle/strangle strategy with intraday stop-loss levels with time-based entry and exits using Algomojo Platform and...
Rajandran R
7 min read

Learn How to Login into Algomojo Account using Amibroker

In the last tutorial, we learn how to automate the algomojo login process and in this video tutorial, we are going to learn with...
Rajandran R
1 min read

Amibroker Execution Module – Hedged Index Futures for Directional…

In the last tutorial, we learn the importance of Hedging Futures Position with OTM Options for Reduced Margin. This tutorial focus on how to...
Rajandran R
14 min read

16 Replies to “Simple AFL code for 5 EMA(High-Low)”

  1. 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.

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

  3. 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

  4. 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.

  5. @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)

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

  7. Sir,

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

    Regards,

    Dipak

  8. 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

  9. Hello Rajendran,

    I want plot buy/sell signal for current day only , i dont’t want signals for previous days.

    pls help me to plot buy/sell signal only for current day.

    Awaiting for your response.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More