Modified Guppy Multiple Moving Average Strategy: Amibroker AFL

Following the Trend is one of the sure-shot methods of making money through financial markets. But it’s important to choose the right set of technical indicators which gives a clear direction to a trend trader. Guppy multiple moving average (GMMA) is one of the most popular and accurate methods to identify the ongoing trend as well as trend reversals. It was developed by Daryl Guppy, an Australian trader who has put years of effort in developing this amazing indicator. In this post, we would explore a trading system based on Guppy multiple moving average. An AFL code is included along with Buy/Sell signals and backtesting results.

Guppy multiple moving average: A Closer Look

GMMA is composed of two sets of exponential moving averages. The first set is based on shorter timeframes of 3, 5, 8, 12, and 15 periods, while the second set uses longer timeframes of 30, 35, 40, 45, and 50 periods. The indicator suggests bullishness when all short-term EMAs cross above all long-term EMAs, and it gives a bearish signal when the short term EMAs cross below the long-term EMAs. The intersection between the two groups of moving averages indicates that a change in the trend occurred. Please note that the timeframes of moving averages are customizable, there is no hard and fast rule.

The shorter timeframe moving averages monitors the trading activity of short term traders, while longer timeframe moving averages monitors how long terms traders play the markets. It’s a smart and reliable method to gauge the overall market sentiment. While it works like wonders for trending stocks, it may not be very accurate for stocks trading sideways. Hence, it should be used with caution only on selected stocks.

We have tested the following system based on GMMA on Banknifty and Nifty, which are usually volatile and trending. The backtest results are quite convincing and the system has performed consistently well since the last 10+ years.

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

Guppy multiple moving average – AFL Overview

Parameter Value
Preferred Time-frame
Daily
Indicators Used EMA (Exponential Moving Average)
Buy Condition Average of (difference between shorter timeframe moving averages and longer timeframe moving averages) aka FastGuppy crosses the smoothed average of FastGuppy from bottom
Short Condition Average of (difference between shorter timeframe moving averages and longer timeframe moving averages) aka FastGuppy crosses the smoothed average of FastGuppy from top
Sell Condition
  • Same as Short
  • Stop Loss Hit
  • Target met
Cover Condition
  • Same as Buy
  • Stop Loss Hit
  • Target met
Stop Loss 1%
Targets 5%
Position Size 10% of Equity
Initial Equity 200000
Brokerage 100 per order
Margin 10%

GMMA Trading System – AFL Code

//------------------------------------------------------
//
//  Formula Name:    Guppy multiple moving average Trading system
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

_SECTION_BEGIN("Guppy multiple moving average Trading system");

SetBarsRequired( sbrAll );
SetChartOptions(0,chartShowArrows|chartShowDates);

//Initial parameters
SetTradeDelays( 1,1,1,1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(10,spsPercentOfEquity);
SetOption( "AllowPositionShrinking", True );


Plot( Close, "Price",colorWhite, styleCandle );

guppy0= ema( close, 3 );
guppy1= ema( close, 5 );
guppy2= ema( close, 8 );
guppy3 = ema( close, 12 );
guppy4 = ema( close, 15 );

g1 = (guppy0+guppy1+guppy2+guppy3+guppy4)/5;

guppy5= ema( close, 30 );
guppy6= ema( close, 35 );
guppy7= ema( close, 40 );
guppy8 = ema( close, 45 );
guppy9 = ema( close, 50 );

g2 = (guppy5+guppy6+guppy7+guppy8+guppy9)/5;

SmoothFactor = param("smooth",5,5,50,1);

FastGuppy = g1-g2;
SlowGuppy = ema(FastGuppy, SmoothFactor);

Buy = Cross(FastGuppy,SlowGuppy);
Short = Cross(SlowGuppy,FastGuppy); 
Sell = Short;
Cover = Buy;

BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

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

printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover );  
printf("\nDoji : " + abs(O-C) ); 

StopLoss=param("SL",1,1,10,1);
Target=param("Target",5,5,40,5);
ApplyStop(Type=0,Mode=1,Amount=StopLoss);
ApplyStop(Type=1,Mode=1,Amount=Target);
 
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

Guppy Multiple Moving Average

Also Read: McGinely Dynamic Trading System

Guppy multiple moving average- Backtest Report

GMMA trading system was backtested on Nifty and Banknifty over a period of 18 years. See the results below:

Parameter Value
Nifty and Banknifty
Initial Capital 200000
Final Capital 5993117.09
Scrip Name NSE Nifty and NSE Banknifty
Backtest Period 05-Apr-2000 to 25-Sep-2018
Timeframe Daily
Net Profit % 2896.56%
Annual Return % 19.89%
Number of Trades 1091
Winning Trade % 33.64%
Average holding Period 4.70 periods
Max consecutive losses 14
Max system % drawdown -24.62%
Max Trade % drawdown -81.96%

Download the detailed backtest report here.

Equity Curve

There are brief period of drawdowns that this system has witnessed, but it has recovered from all the losses quickly

GMMA_Equity_Curve

Profit Table

GMMA_Profit_Table

Additional Amibroker settings for backtesting

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

Symbol Info_Nifty

Banknifty Symbol Information

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

4 Comments

  1. Some of the points need clarifications,
    1.In the AFL code section, 5 sets of each short and long time frames are used while in the article 6 sets are advised.
    2, Short time frames of 3,5,8,10,12,18 are there in the article while in the AFL code 3,5,8,12,15 are used
    3.Long term time frame: 60 is skipped in AFL code
    5. Kindly through some light on how the average of long time frame is smothered in excel sheet.

    Thank you

    • Hi Shailendra,

      All the mentioned points are valid and corrected in the post. Thanks for your keen observation and feedback

  2. Hi,
    EMA18, crossing EMA60 will also give same results. So, what is purpose of using so many?
    Can you compare the results.?

    • Using multiple moving averages gives more accurate results and lesser whipsaws. This is the primary idea behind Guppy moving averages

Leave a Reply

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