AFL for MACD Strategy

MarketSecrets - Learn To Trade Like a Pro

AFL for MACD Strategy

The trading idea is to buy when a) trend is strong b) there is momentum in market c) the market is not sideways

The MACD indicator is one of the most popular indicators to determine trending prices.  The basic trading rules is to buy when it cuts above zero line or buy when its cuts above signal line. When the direction of trend is not clear, MACD stays close to the zero line. Hence we use smooth MACD(30,50,60) to determine trend and do no trade when it’s value is between -25 to +25 (close to zero).

When the market is dull, the prices move slowly and seldom go beyond their standard deviation levels. So we use Bollinger Band(20,1) to filter out signals generated when prices are between them.

Buy: MACD>0 and MACD> Signal Line and MACD>25 and Signal candle is beyond Bollinger Band
Sell:  When either MACD<0 or MACD< Signal Line

Script:

_SECTION_BEGIN( “MACD AFL” );

SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, “Close”, ParamColor( “Color”, colorBlack ), styleNoTitle | ParamStyle( “Style” ) | GetPriceStyle() );

SetBarsRequired( 100000, 0 );

per1 = Param( “MACD Fast”, 20, 1, 100, 1 );
per2 = Param( “MACD Slow”, 50, 1, 100, 1 );
per3 = Param( “Signal Line”, 40, 1, 100, 1 );
per4 = 20;
per5 = 1;
bbtop = BBandTop( C, per4, per5 );
bbot = BBandBot( C, per4, per5 );

SetPositionSize( 1, spsShares );

MACD1 = MACD( per1, per2 );
sig = Signal( per1, per2, per3 );

Buy = MACD1 > 0 AND MACD1 > sig  AND L > bbtop  AND MACD1 > 25 ;
Sell = MACD1 < 0 OR MACD1 < sig;

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

Short = MACD1 < 0 AND MACD1 < sig AND H < bbot AND MACD1 < -25 ;
Cover = MACD1 > 0 OR MACD1 > sig;

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

Title = NumToStr( DateTime(), formatDateTime ) + ” O ” + O + ” H ” + H + ” L ” + L + ” C ” + C
        ;
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( Sell, shapeDownArrow, shapeNone ), colorRed, 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 );
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), colorBlue, 0, L, Offset = -45 );

_SECTION_END();

 

Download AFL

error: Content is protected !!