mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

How to change the number of chart-bar?

Open chanmoto opened this issue 3 years ago • 1 comments

Currently, the duration of the bar is automatically replaced by the number of arrays. Thus, the left side of the moving average will be blank. How do I draw a moving average from one end to the other? How to change the number of chart-bar manually?

chanmoto avatar Feb 01 '22 04:02 chanmoto

Moving averages require, initially, at least as many data points as the moving average window, in order to calculate the first moving average point. Thus the "gap" at the begining of the plot. There are two ways to avoid the gap at the beginning of the plot. Both methods involve having data earlier in time than what is actually plotted. This ealier data is not plotted, but is used to calculated the moving average.

The two ways to do this are:

  1. Let mplfinance calculate the moving average (using the mav kwarg) and use the xlim kwarg to set the xlimits so that data before the the first moving average point is not plotted.

  2. Calculate your own moving average (outside of mplfinance) and use mpf.make_addplot() to plot the moving average, but plot data only after where the moving average begins.

Click here for further details.

DanielGoldfarb avatar Feb 01 '22 12:02 DanielGoldfarb