AFL of the week: 14-73 EMA crossover system

We are very excited to start this new section on our website called  ‘AFL of the week‘. Every Amibroker enthusiast spends days and weeks to code a profitable AFL. And the folks who are not familiar with programming end up paying thousands of bucks to purchase AFL’s, most of which turns out to be a scam. In this section, we’ll try to assist all these people by posting profitable AFL’s and trading systems. This would save both their time and money. We’ll post copy-paste enabled AFL code and the backtest report (whenever applicable). Believe me, there are no hidden terms and conditions here. Just stay tuned for a new AFL every week. Subscribe to our blog from the right-hand side of this page so that you get notifications right in your mailbox.

Please visit Trading Tuitions Academy to learn AFL coding and create your own Trading systems.

The 14-73 EMA Crossover system

This is a moving average crossover  strategy which works tremendously well in trends and gives small losses during trading ranges. We have tested this in Daily timeframe on highly liquid indices like Nifty and BankNifty.

AFL Overview

ParamterValue
Preferred TimeframeDaily
Indicators Used14 period EMA, 73 period EMA
Buy Condition14 period EMA crosses above 73 period EMA (Buy at next day Open)
Sell Condition14 period EMA crosses below 73 period EMA (Sell at next day Open)
Stop LossNo fixed stoploss, Stop and reverse when AFL gives opposite signal
TargetsNo fixed target, Stop and reverse when AFL gives opposite signal
Position Size150 (fixed)
Initial Equity200000
Brokerage50 per order
Margin10%

AFL Code

//------------------------------------------------------
//
//  Formula Name:    14-73 Crossover Trading System
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

_SECTION_BEGIN("14-73 Crossover Trading System");

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


//Initial Parameters

SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",50);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(150,spsShares);
SetOption( "AllowPositionShrinking", True );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

//Parameters

MALength1 = 14;
MALength2 = 73;

//Buy-Sell Logic

Buy = Cross(ema( C, MALength1 ),ema( C, MALength2 ));
Sell =Cross( ema( C, MALength2 ), ema( C, MALength1 )) ;

Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Short = Sell;
Cover = Buy;


Plot( Close, "Price", colorWhite, styleCandle );
Plot(ema( C, MALength1 ),"FastEMA",colorWhite);
Plot(ema( C, MALength2 ),"SlowEMA",colorBlue);

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);


_SECTION_END();

AFL Screenshot

14-73 EMA CA

Backtest Report

 ParamterValue
  NiftyBank Nifty
Initial Capital 200000 200000
Final Capital 7087401727157.50
Backtest Period02-Jan-2007 to 09-02-201602-Jan-2007 to 09-02-2016
Net Profit % 254.37% 763.58%
Annual Return %14.90%26.70%
Number of Trades3636
Winning Trade %22.22%38.89%
Average holding Period61.28 periods60.92 periods
Max consecutive losses94
Max system % drawdown-59.29%-59.40%
Max Trade % drawdown-22.08%-97.77%

Download the detailed backtest report here.

Equity Curve

Nifty:

Equity Curve- Nifty

Bank Nifty:

Equity Curve- BNF

Additional Amibroker settings for backtesting

Goto Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows lot size of 30 and margin requirement of 10% for Bank Nifty:

Symbol Info

Disclaimer:

All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

Related Posts

One Comment

  1. Hello Sir!
    Can this strategy be applied in excel too.
    And in Zerodha PI if you could share the tradescript with entering & exit codes.

Leave a Reply

Your email address will not be published. Required fields are marked *