anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.14k stars 557 forks source link

Bug with the shadows when using Renko chart types? (an image, source data and a source code included) #207

Open ProgrammingLife opened 4 years ago

ProgrammingLife commented 4 years ago

Maybe I'm using this part of library incorrect? I've attached my source code, source data and the image as a output for that data. It looks like:

And my source code is:

let json = '[{"time":1551398400,"open":3814.26,"high":3857,"low":3813.01,"close":3823,"volume":23175,"mainPrice":3823},{"time":1551484800,"open":3822.17,"high":3841.31,"low":3772.25,"close":3819.93,"volume":19446,"mainPrice":3819.93},{"time":1551571200,"open":3819.97,"high":3835,"low":3781.32,"close":3807.75,"volume":16718,"mainPrice":3807.75},{"time":1551657600,"open":3807.32,"high":3830,"low":3670.69,"close":3715.3,"volume":34743,"mainPrice":3715.3},{"time":1551744000,"open":3716.1,"high":3877.1,"low":3703.55,"close":3857.73,"volume":32963,"mainPrice":3857.73},{"time":1551830400,"open":3857.58,"high":3907,"low":3813.09,"close":3861.84,"volume":24775,"mainPrice":3861.84},{"time":1551916800,"open":3861.84,"high":3905.4,"low":3840.4,"close":3873.64,"volume":26455,"mainPrice":3873.64},{"time":1552003200,"open":3873.63,"high":3932,"low":3800,"close":3864.89,"volume":34730,"mainPrice":3864.89},{"time":1552089600,"open":3864.88,"high":3971.75,"low":3854.75,"close":3943.04,"volume":30980,"mainPrice":3943.04},{"time":1552176000,"open":3943.43,"high":3943.43,"low":3881.69,"close":3916.82,"volume":23188,"mainPrice":3916.82},{"time":1552262400,"open":3915.99,"high":3936.98,"low":3830,"close":3871.61,"volume":38067,"mainPrice":3871.61},{"time":1552348800,"open":3871.61,"high":3905.2,"low":3826.06,"close":3882.73,"volume":26921,"mainPrice":3882.73},{"time":1552435200,"open":3882.69,"high":3893.56,"low":3840,"close":3866,"volume":24461,"mainPrice":3866},{"time":1552521600,"open":3866,"high":3920,"low":3810.43,"close":3877.12,"volume":27049,"mainPrice":3877.12},{"time":1552608000,"open":3877.12,"high":3939.22,"low":3872.2,"close":3923.76,"volume":21740,"mainPrice":3923.76},{"time":1552694400,"open":3924.46,"high":4056.98,"low":3921.98,"close":4005.98,"volume":28568,"mainPrice":4005.98},{"time":1552780800,"open":4005.98,"high":4012,"low":3950.01,"close":3981.14,"volume":18814,"mainPrice":3981.14},{"time":1552867200,"open":3981.85,"high":4037,"low":3953.33,"close":3987.81,"volume":22454,"mainPrice":3987.81},{"time":1552953600,"open":3987.83,"high":4031,"low":3970,"close":4015.53,"volume":19894,"mainPrice":4015.53},{"time":1553040000,"open":4017.48,"high":4050,"low":3980.5,"close":4043.04,"volume":23432,"mainPrice":4043.04}]';
let quotes = JSON.parse(json);
let quotesCount = quotes.length;

let renkoOriginalData = {
    ticker: "TICKER",
    timestamp: [],
    open: [],
    high: [],
    low: [],
    close: [],
    volume: [],
};
for (let i = 0; i < quotesCount; i++) {
    renkoOriginalData.timestamp.push(parseInt(quotes[i].time));
    renkoOriginalData.open.push(quotes[i].open);
    renkoOriginalData.high.push(quotes[i].high);
    renkoOriginalData.low.push(quotes[i].low);
    renkoOriginalData.close.push(quotes[i].close);
    renkoOriginalData.volume.push(quotes[i].volume);
}

let renko = new technicalIndicators.renko(Object.assign({}, renkoOriginalData, { brickSize: 10, useATR: false }));

let chartCandlesticks = [];
for (let i = 0; i < renko["open"].length; i++) {
    chartCandlesticks.push({
        time: renko["timestamp"][i],
        open: renko["open"][i],
        high: renko["high"][i],
        low: renko["low"][i],
        close: renko["close"][i],
    });
}

// plotting the chartCandleSticks

Why do I get such strange shadows?

ProgrammingLife commented 4 years ago

If I use just for testing purposes this: let renko = new technicalIndicators.HeikinAshi(renkoOriginalData).result;

all works fine. Shadows place in the right places. Looks like the issue only with the Renko chart type. Is this my fault?