31.07.2021 Views

Ultimate Algorithmic Trading System

Using automated systems for trading in stock markets

Using automated systems for trading in stock markets

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Based on our knowledge of the MACD and the chart examples, Box 2.7 shows a

simple MACD histogram-trading algorithm.

56

STOCHASTICS AND AVERAGES AND RSI! OH, MY!

Box 2.7 Gerald Appel’s MACD Histogram System

Notice how the algorithm description in this example is getting closer and closer

to pseudocode. As you evolve as a system tester, you will notice how the lines

that separate description, pseudocode, and actual code start to blur. LeftBar2 is

the second bar to the left of the pivot high/low bar and LeftBar1 is the first bar

to the left of the pivot. The other variable names should be self-explanatory.

myMACD = MACD(C,12,26)

myMACDAvg = Xaverage(MACD,9)

myMACDDiff = myMACD − myMACDAvg

leftBar2 = myMACDDiff[4]

leftBar1 = myMACDDiff[3]

centerBar = myMACDiff[2]

rightBar1 = myMACDDiff[1]

rightBar2 = myMACDDiff[0]

If leftBar2 < 0 and rightBar2 < 0 and centerBar < leftBar1 and centerBar

< leftBar2 and centerBar < rightBar1 and centerBar < rightBar2, then

Buy MOC

If leftBar2 > 0 and rightBar2 > 0 and centerBar > leftBar1 and centerBar

> leftBar2 and centerBar > rightBar1 and centerBar > rightBar2, then

SellShort MOC

If position is long

Take Profit: If close > entry price + 3 ATR Sell MOC

Protective Stop: If close < entry price − 1 ATR Sell MOC

If position is short

Take Profit: If close < entry price − 3 ATR BuyToCover MOC

Protective Stop: If close > entry price + 1 ATR, BuyToCover MOC

*MOC = market on close

Gerald Appel’s MACD Histogram System p – code

‘Gerald Appels MACD histogram algorithm

‘Buys – histogram forms a low 2 bar pivot with all bars below 0

‘Shorts – histogram forms a high 2 bar pivot with all bars above 0

www.rasabourse.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!