matplotlib / mplfinance

Financial Markets Data Visualization using Matplotlib
https://pypi.org/project/mplfinance/
Other
3.68k stars 633 forks source link

`tz_localize=True` fails to localize datetimes in `tlines` and `alines` specifications (and in the future also in xlim specification?) #314

Open ventek opened 3 years ago

ventek commented 3 years ago

Hi, I tried to implement the tlines using mplfinance, and generate the trendline data as per the example, however, I still get this error:

ValueError: tlines date pair (2021-01-11 09:35:00-05:00,2021-01-11 10:20:00-05:00) too close, or wrong order, or out of range! df date range: [2021-01-11 09:35:00+00:00 , 2021-01-11 10:20:00+00:00]

Please, if anyone can advise, It will be much appreciated.

Regards.

DanielGoldfarb commented 3 years ago

I'm guessing the problem is that you have different timezone information in your tlines datetimes compared with your DataFrame DatetimeIndex, and so it thinks that the times you specified with tlines are outside of the range of the DatetimeIndex in your DataFrame.

If the above is not enough information to solve your problem, then please post your data (csv file), and your code, so that I can try to reproduce this.

All the best. --Daniel

ventek commented 3 years ago

Hi Daniel, Thanx for the quick response, I have sent an email with the csv and code.

DanielGoldfarb commented 3 years ago

Hi Daniel, Thanx for the quick response, I have sent an email with the csv and code.

Got it. I will try to make time to look into this today. I suspect that it may have something to do with the fix for this timezone bug.

In the meantime, until I get a chance to look at this, please try adding kwarg tz_localize=False to your call to mpf.plolt() and let me know if that fixes the problem. Thanks.

ventek commented 3 years ago

Hi Daniel, Adding tz_localize=False solved the problem.

Thank you so much for the assistance.