The AIQ code for finding head & shoulders (H&S) patterns based on Giorgos Siligardos’ article in the May issue of Stocks & Commodities, “Head & Shoulders, Algorithmically (Part 2),” is provided at the following website: www.TradersEdgeSystems.com/traderstips.htm.
I did not directly translate the code given in Siligardos’ article into AIQ EDS code because the AIQ program has chart pattern recognition built in. The code I am providing will find H&S patterns — as well as many other patterns — for either completed or emerging patterns.
In Figure 5, I show an example of a completed H&S topping pattern with the sell signal (red down arrow). The bars after the signal indicate that this trade was immediately profitable. In Figure 2, I show an example of a completed inverse H&S bottoming pattern with a buy signal (red up arrow). The bars after the signal indicate that this trade was immediately profitable.
The code and EDS file can be downloaded from www.TradersEdgeSystems.com/traderstips.htm, and is shown below.
!DETECTING HEAD & SHOULDERS ALGORITHMICALLY !Author: Giorgos E. Siligardos TASC May 2013 !Coded by: Richard Denning 3/17/2013 !USER DEFINED FUNCTIONS: C is [close]. Name is description(). !COMPLETED HEAD & SHOULDERS PATTERN-TOPPING: HS is [Head and Shoulders]. HS_breakoutup if HS > 0. HS_breakoutdn if HS < 0. !COMPLETED HEAD & SHOULDERS PATTERN-INVERTED: iHS is [Inv Head and Shoulders]. iHS_breakoutup if iHS > 0. iHS_breakoutdn if iHS < 0. !EMERGING HEAD & SHOULDERS PATTERN-TOPPING: e_HS is [eHead and Shoulders]. e_HSemerge if e_HS > 0 or e_HS < 0. !EMERGING HEAD & SHOULDERS PATTERN-INVERTED: e_iHS is [eInv Head and Shoulders]. e_iHSemerge if e_iHS > 0 or e_iHS < 0. !REPORTS TO LIST ALL HEAD & SHOULDERS PATTERS: ShowAll if C>0 and (HS <> 0 or iHS <> 0 or e_HS <> 0 or e_iHS <>0).