Skip to main content

The Profitable Approach of Trend Following

Trend following is a reliable strategy for making money in both rising and falling markets. However, during sideways trends, it can be challenging due to consecutive false signals, which are hard to avoid. One way to mitigate this is by using a combination of indicators. We’ll delve into an intraday trend-following strategy that effectively combines MACD and Bollinger Bands to identify potential trading opportunities.

Read Also: Bollinger Bands- Unofficed

MACD helps determine the market’s direction (uptrend or downtrend), while Bollinger Bands assist in capturing strong trends and avoiding unnecessary false signals. This strategy is designed solely for intraday trading, with no overnight positions held. It has demonstrated a commendable success rate within a 5-minute timeframe, achieving an impressive CAGR of around 40% during a 4-year backtesting period.

If you wish to explore AFL coding and create your trading systems, click here.

An Overview of the Intraday Trend Following Strategy – AFL

ParameterValue
Preferred Time-frame5 Minutes
Indicators UsedMACD (12,26,9), Bollinger Bands (20,3)
Buy Condition
  • MACD Line Crosses the signal line upwards.
  • MACD Histogram is greater than 0.
  • Close is higher than the Bollinger Band Top.
Short Condition
  • MACD Line Crosses the signal line downwards.
  • MACD Histogram is less than 0.
  • Close is lower than the Bollinger Band Bottom.
Sell Condition
  • Same as Short.
  • Stop Loss is triggered.
  • Target is met.
  • End of Trading Day.
Cover Condition
  • Same as Buy.
  • Stop Loss is triggered.
  • Target is met.
  • End of Trading Day.
Stop Loss0.5%
Targets3%
Position Size150 Quantities
Initial Equity200,000
Brokerage100 per order
Margin10%

AFL Code

				
					//------------------------------------------------------
//
//  Formula Name:    Intraday Trend Following Strategy
//  Website:         https://zerobrokerageclub.com/
//------------------------------------------------------

_SECTION_BEGIN("MACD Intraday Trend Following Strategy"); 

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(100,spsPercentOfEquity);
SetOption( "AllowPositionShrinking", True );
SetOption("MaxOpenPositions",10);
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));
Plot( Close, "Price", colorWhite, styleCandle );

NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0;  
Plot(NewDay,"",colorlightGrey,styleHistogram|styleDots|styleNoLabel|styleOwnScale);

FirstTradeTime=093000;
SquareOffTime = 151500;

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
 
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
Hist= ml-sl;

Periods = Param("Periods", 20, 10, 100, 10 );
Width = Param("Width", 3, 1, 10, 1 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
Plot( BBandTop( C, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( BBandBot( c, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); 

 
Buy= Cross(ml , sl) AND Hist>0 AND TimeNum()>= FirstTradeTime AND Close>BBandTop( C, Periods, Width ) AND TimeNum()<= SquareOffTime ;

Short= Cross(sl , ml) AND Hist<0 AND TimeNum()>= FirstTradeTime AND Close<BBandBot( C, Periods, Width ) AND TimeNum()<= SquareOffTime ;

Cover=buy OR TimeNum() >= SquareOffTime;

Sell=Short OR TimeNum() >= SquareOffTime;

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

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

StopLoss=Param("stop",0.5,0.5,3,0.5);
ApplyStop(Type=0,Mode=1,Amount=StopLoss);

Target=Param("Target",3,0.5,5,0.5);
ApplyStop(Type=1,Mode=1,Amount=Target);

printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover ); 
printf("\nml : " + ml ); 
printf("\nsl : " + sl ); 
printf("\nHist : " + Hist ); 

/* 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

Backtest Report Parameters for the Intraday Trend Following Strategy

Parameter Value
Nifty
Initial Capital 200,000
Final Capital 1,075,018.50
Scrip Name NSE Nifty
Backtest Period 8-Feb-2012 to 21-Nov-2016
Timeframe 5 Minutes
Net Profit % 437.51%
Annual Return % 40.80%
Number of Trades 106
Winning Trade % 67.92%
Average Holding Period 24.20 periods
Max Consecutive Losses 4
Max System % Drawdown -13.03%
Max Trade % Drawdown -8.13%
You can download the detailed backtest report here.

Equity Curve

Profit Table

This intraday trend following strategy has been profitable every year from 2012 to 2016.

Additional Amibroker Settings for Backtesting

Go to Symbol –> Information and specify the lot size and margin requirement. The screenshot below shows a lot size of 75 and a margin requirement of 10% for NSE Nifty.

2 Comments

Leave a Reply