check with Zup harmonic pattern indicator, it includes equation for more than 40 pattern.
I think the problem with converting from "String" to "Double" could you tell us more about your idea, or what should be the output of "W".