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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Now, switching gears and using the CCI as a coincident indicator, Box 2.6

provides the description of a trend-following algorithm. A coincident indicator

simply means it is confirming the current market direction.

52

STOCHASTICS AND AVERAGES AND RSI! OH, MY!

Box 2.6 Donald Lambert’s CCI Trend-Following System

myCCIVal = 9-day average of the 20-day CCI

If the lowest myCCIVal for the past 3 days > 100, then

Buy MOC

If the highest myCCIVal for the past 3 days < −100, then

Sell Short MOC

If position is long

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

Protective Stop: If close < entry price − 3ATR,SellMOC

If position is short

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

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

Note that MOC stands for market on close.

Donald Lambert’s CCI Trend-Following System p − code

myCCIVal = average(cci(cciLen),smooth);

If lowest(myCCIVal,3) > 100 then buy this bar on close;

If highest(myCCiVal,3) < -100 then sellShort this bar on

close;

If marketPosition = 1 then

If c > entryPrice + 5* avgTrueRange(10) then sell this

bar on close

if c < entryPrice - 3* avgTrueRange(10) then sell this

bar on close

If marketPosition =-1 then

If c < entryPrice - 5* avgTrueRange(10) then buyToCover

this bar on close

if c > entryPrice + 3* avgTrueRange(10) then buyToCover

this bar on close

This trading algorithm description is somewhat different from the others we have

thus discussed in this chapter. Instead of repeating the words for the 9-day average

of the 20-day CCI, I simply assigned it to the variable myCCIVal. This is just like

you would do in an actual programming language. The words lowest and highest were

also introduced and used as a shortcut to see if the myCCIVal variable was above or

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!