How to change the number of chart-bar?
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?
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:
-
Let mplfinance calculate the moving average (using the
mavkwarg) and use thexlimkwarg to set the xlimits so that data before the the first moving average point is not plotted. -
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.