diff --git a/src/mplfinance/plotting.py b/src/mplfinance/plotting.py index 2fecd8c3..5b5ca3c2 100644 --- a/src/mplfinance/plotting.py +++ b/src/mplfinance/plotting.py @@ -1196,6 +1196,8 @@ def _plot_mav(ax,config,xdates,prices,apmav=None,apwidth=None): mavc = config['_ma_color_cycle'] + list_ploted_mav =[] + for idx,mav in enumerate(mavgs): mean = pd.Series(prices).rolling(mav).mean() if shift is not None: @@ -1204,9 +1206,14 @@ def _plot_mav(ax,config,xdates,prices,apmav=None,apwidth=None): lw = config['_width_config']['line_width'] if mavc: ax.plot(xdates, mavprices, linewidth=lw, color=next(mavc)) + list_ploted_mav.append(mean.values[-1].round(1)) else: ax.plot(xdates, mavprices, linewidth=lw) + list_ploted_mav.append(mean.values[-1].round(1)) mavp_list.append(mavprices) + yticks_mav = [*ax.get_yticks()] + list_ploted_mav + yticklabels_mav = [*ax.get_yticklabels()] + list_ploted_mav + ax.set_yticks(yticks_mav, labels=yticklabels_mav) return mavp_list @@ -1230,6 +1237,8 @@ def _plot_ema(ax,config,xdates,prices,apmav=None,apwidth=None): mavc = config['_ma_color_cycle'] + list_ploted_ema =[] + for idx,mav in enumerate(mavgs): # mean = pd.Series(prices).rolling(mav).mean() mean = pd.Series(prices).ewm(span=mav,adjust=False).mean() @@ -1239,9 +1248,14 @@ def _plot_ema(ax,config,xdates,prices,apmav=None,apwidth=None): lw = config['_width_config']['line_width'] if mavc: ax.plot(xdates, emaprices, linewidth=lw, color=next(mavc)) + list_ploted_ema.append(mean.values[-1].round(1)) else: ax.plot(xdates, emaprices, linewidth=lw) + list_ploted_ema.append(mean.values[-1].round(1)) mavp_list.append(emaprices) + yticks_ema = [*ax.get_yticks()] + list_ploted_ema + yticklabels_ema = [*ax.get_yticklabels()] + list_ploted_ema + ax.set_yticks(yticks_ema, labels=yticklabels_ema) return mavp_list