1. ok so how would I code candle body is less than 30%, which would make it a hammer or an inverse hammer candle in the above image???
Ok you mean the body vs the high/low range? (Math.Abs(Open-Close)<0.3*(High-Low))
2. also how would I code if there is a gap between 2 candles like the morningstar 3 candle pattern in the above image?
for going down: (Open<Math.Min(Open, Close))
3. Also, how would I code a Doji or Spinning Top Candle.
You would have to clearly define what Doji candle is. If it is one where there are wicks, but no body, it would be something like
(Open==Close && High>Close && Low<Close)