technicalindicators icon indicating copy to clipboard operation
technicalindicators copied to clipboard

Dojis seem too loosely defined

Open jwenzler opened this issue 7 years ago • 3 comments

Hello, this is an amazing repo, just something I've noticed.

The following candlestick is coming back as a doji.
screen shot 2017-08-22 at 12 49 17 am

I think this is simply because of the approximateEqual function. I haven't yet worked on a more accurate version, but in this case...

approximateEqual(1.36171, 1.36079) = true

jwenzler avatar Aug 22 '17 05:08 jwenzler

A quick possibility could be creating a separate function for dojis that considers the extremes (low and high).

function approximateEqualWithExtremes(a:number, b:number, low:number, high:number):boolean {
        const totalDiff = high - low;
	const diff = Math.abs(b - a);
	return diff / totalDiff < .1;
}

Where we take the whole range for the candlestick and see if the open to close diff is less than 10% of the total height.

So in this case something like...

approximateEqualWithExtremes(1.36171,1.36079,1.36053,1.36174) = false

jwenzler avatar Aug 22 '17 05:08 jwenzler

sure. Can you create a pull request with this change only for doji?

anandanand84 avatar Aug 22 '17 11:08 anandanand84

I have been an R guy all along and picked up JS recently. I have used the candleStick Pattern package built in R by R-Forge. Please see the JS equivalent of their implementation of Doji

DOJI:

        const bl = Math.abs(data.close[0] - data.open[0]);
        const cl = data.high[0] - data.low[0];
        return (bl<cl*0.1);

GRAVESTONE DOJI:

        const bl = Math.abs(data.close[0] - data.open[0]);
        const cl = data.high[0] - data.low[0];
        //const bodyHi = Math.max(data.open[0], data.close[0])
        const bodyLo = Math.min(data.open[0], data.close[0])
        return ((bl<cl*0.1) && ((bodyLo - data.low[0]) <= cl * 0.1));  

DRAGONFLYDOJI:

        const bl = Math.abs(data.close[0] - data.open[0]);
        const cl = data.high[0] - data.low[0];
        const bodyHi = Math.max(data.open[0], data.close[0])
        //const bodyLo = Math.min(data.open[0], data.close[0])
        return ((bl<cl*0.1) && ((data.high[0] - bodyHi) <= cl * 0.1));

GoChartingAdmin avatar Sep 27 '17 20:09 GoChartingAdmin