Modified version of HPotter's "Doji and Near Doji automatic finding script".
Candles are classified based on not just the size of the body but also the distance from the close to the high/low. This avoids classifying a reversal candle with a long wick but a strong close as a doji.