Incorrect operation of add_ohlc with a "while" loop

Hi.
I need to paint each ohlc a custom color. I do this through a โ€œwhileโ€ loop, building each bar separately and assigning a color to it. But in this case, closing and opening prices are not displayed.

It seems to me that the separate trace ohlc overlaps each other.
Is there any solution to this problem?

Code:

I think problem is in the โ€œtickwidthโ€ property, so there are opening and closing prices if you scale the x axis enough.
If you replace the x-axis from date to int, then everything will be displayed correctly.

Date x axis:

Is there any way to fix it?