Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Intraday Trend Following Strategy using MACD and Bollinger Band for Amibroker (AFL)

Rating:
3 / 5 (Votes 2)
Tags:
macd, intraday, oscillator, amibroker

Trend following is certainly a sure-shot way to mint money during rising or falling markets. At sideways trend it can be painful due to consecutive whipsaws but there is no way to avoid that. The only thing we can try is to minimize whipsaws using combination of indicators. The intraday trend following strategy that we are going to discuss uses combination of MACD and Bollinger Bands to indicate trading opportunities. MACD is used to identify the direction of market (uptrend or downtrend) while Bollinger bands are used to catch only strong trends and avoid unnecessary whipsaws. This is a pure intraday strategy as none of the positions are carried forward. The strategy has a decent success rate in 5 minutes timeframe. Also, the CAGR of 40%~ in 4 years backtesting period is commendable.

Read more about this strategy and download the backtest report here.

Screenshots

Indicator / Formula

Copy & Paste Friendly
//------------------------------------------------------
//
//  Formula Name:    Intraday Trend Following Strategy
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.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;
Sell=short OR TimeNum() >= SquareOffTime;
Cover=buy 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();

4 comments

1. singhshashwat

It shows a syntax error at Line:18. Could you kindly double check

2. joeoil

No, it’s not any syntax error in the code.

I have Amibroker v. 5.90.

3. sureshsellappan

is not good

4. ken20111

Hello, I found your formula is very useful if do it reversely, may i ask your to write one to do that? thx a lot

Leave Comment

Please login here to leave a comment.

Back