The AIQ code based on James and John Rich’s article in the November 2015 issue of Technical Analysis of STOCKS & COMMODITIES, “Simplify It,” is provided at www.TradersEdgeSystems.com/traderstips.htm.
The code I am providing matches the description of the authors’ trend-following system with additional exit rules. The long exit has an additional profit-protect exit that is not coded, but when I ran tests, I used the built-in profit-protect exit set to 80% protection once the profit level reaches 5% or greater.
FIGURE 9: AIQ. Here is a sample equity curve of the trend-following system versus the NASDAQ 100 index for the period 1/2/2000 to 11/06/2015.
Figure 9 shows the equity curve for the system versus the NASDAQ 100 index for the period 1/2/2000 to 11/06/2015. Figure 10 shows the metrics for this same test period. The system clearly outperformed the index.
FIGURE 10: AIQ. Here are the metrics for the trend-following system and the test settings.
The code and EDS file can be downloaded from www.TradersEdgeSystems.com/traderstips.htm, and is also shown below.
!SIMPLIFY IT !Author: James E. Rich with John B. Rich, TASC Nov 2015 (for Jan 2016) !Coded by: Richard Denning 11/1/2015 !www.TradersEdgeSystems.com !INPUTS mktTrendLen is 50. IDX is "SPY". stkLen1 is 20. stkLen2 is 50. stkLen3 is 200. trdBandLen is 8. pctStp is 0.07. minBarsSinceBandCross is 10. maxBarsHold is 10. !MARKET DIRECTION: mktClose is TickerUDF(IDX,[close]). mktSMA is simpleavg(mktClose,mktTrendLen). mktTrendUp if mktClose > mktSMA and mktSMA > valresult(mktSMA,10). mtkTrendDn if mktClose < mktSMA and mktSMA < valresult(mktSMA,10). !mktTrendUp if tickerRule(IDX,stkTrendUp). !mtkTrendDn if tickerRule(IDX,stkTrendDn). !STOCK SCREEN FOR UP TRENDING STOCKS: stkSMA1 is simpleavg([close],stkLen1). stkSMA2 is simpleavg([close],stkLen2). stkSMA3 is simpleavg([close],stkLen3). stkTrendUp if [close] > stkSMA2 and stkSMA1 > stkSMA2 and stkSMA2 > stkSMA3 and [close] > 5 and simpleavg([volume],50) > 10000. !volume in hundreds !STOCK SCREEN FOR DOWN TRENDING STOCKS: stkTrendDn if [close] < stkSMA2 and stkSMA1 < stkSMA2 and stkSMA2 < stkSMA3 and simpleavg([volume],50) > 10000. !volume in hundreds !TRADING BANDS: stkSMAhi is simpleavg([high],trdBandLen). stkSMAlo is simpleavg([low],trdBandLen). Buy if mktTrendUp and stkTrendUp and [close] > stkSMAhi and countof([close] > stkSMAhi,minBarsSinceBandCross)=1. Short if mtkTrendDn and stkTrendDn and [close] < stkSMAlo and countof([close] < stkSMAlo,minBarsSinceBandCross)=1. PD is {position days}. PEP is {position entry price}. ExitBuy if [close] < stkSMAlo * (1-pctStp). ExitShort if [close] > stkSMAhi * (1+pctStp) or (PD > maxBarsHold and [close] > PEP).