Black Lives Matter. Please consider donating to Black Girls Code today.

Candlestick candle color problem

I have a problem with candles, I have a candlestick chart generated from csv, in some candles colors are reversed. Open and close values ​​are correct, but the color is the opposite .
For example : close value greater than open value, the color should be green, but it is red .
What could be causing this problem ?

Can you share a code snippet showing what you’ve tried so far?

https://jsfiddle.net/95xmbj5f/
This is the fiddle. Here there are no errors, I have included only 20 candles, but on my program are 100, the values of the candles are selected from five arrays of about 10000-20000 values. The creation of the chart is standard, I included only graphic changes for the background. I post a picture of my program (where there are the same values of the fiddle) to show the wrong candles.