mplfinance Change Color Depending on Value Is Positive or Negative

Nov 2, 2020
import yfinance as yfimport mplfinance as mpfimport talib as taticker_name = 'MSFT'yticker = yf.Ticker("MSFT")data = yticker.history(period="1y") # max, 1y, 3mo# trim volume to avoid exponential formdata['Volume'] = data['Volume'] / 1000# macddata["macd"], data["macd_signal"], data["macd_hist"] = ta.MACD(data['Close'])# macd panelcolors = ['g' if v >= 0 else 'r' for v in data["macd_hist"]]macd_hist_plot = mpf.make_addplot(data["macd_hist"], type='bar', panel=1, color=colors) # color='dimgray'# plotmpf.plot(data, type='candle', style='yahoo', addplot=macd_hist_plot, title=f"\n{ticker_name}", ylabel='')

mplfinance change color

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.