Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/mplfinance/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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


Expand All @@ -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()
Expand All @@ -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


Expand Down