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
Parameter | Value |
Preferred Time-frame | 5 Minutes |
Indicators Used | MACD (12,26,9), Bollinger Bands (20,3) |
Buy Condition |
|
Short Condition |
|
Sell Condition |
|
Cover Condition |
|
Stop Loss | 0.5% |
Targets | 3% |
Position Size | 150 Quantities |
Initial Equity | 200,000 |
Brokerage | 100 per order |
Margin | 10% |
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= 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% |
2 Comments