technicalindicators
technicalindicators copied to clipboard
Dojis seem too loosely defined
Hello, this is an amazing repo, just something I've noticed.
The following candlestick is coming back as a doji.
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
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
sure. Can you create a pull request with this change only for doji?
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));