As mentionedmentioned elsewhereelsewhere on this site, Lo, Mamaysky, and Wang (2000) do exactly what you're talking about, namely algorithmic detection of head and shoulders patterns. Their definition:
Head-and-shoulders (HS) and inverted head-and-shoulders (IHS) patterns are characterized by a sequence of five consecutive local extrema $E_1,...,E_5$ such that
$$ HS \equiv \begin{cases} E_1 \text{ is a maximum} \\ E_3 > E_1, E_3 > E_5 \\ E_1\text{ and }E_5\text{ are within 1.5 percent of their average} \\ E_2\text{ and }E_4\text{ are within 1.5 percent of their average,} \end{cases} $$
$$ IHS \equiv \begin{cases} E_1\text{ is a minimum} \\ E_3<E_1, E_3 < E_5 \\ E_1\text{ and }E_5\text{ are within 1.5 percent of their average} \\ E_2\text{ and }E_4\text{ are within 1.5 percent of their average.} \end{cases} $$