CodeForFinance
Python Tutorial

Create Candlestick Charts with Python

Build professional OHLC candlestick charts with volume, moving averages, and technical indicators using mplfinance.

Install

pip install mplfinance yfinance

Basic Candlestick

import mplfinance as mpf
import yfinance as yf

# Download 3 months of data
data = yf.download("AAPL", period="3mo")

# Basic candlestick chart
mpf.plot(data, type="candle", volume=True, 
         title="AAPL — 3 Month Candlestick",
         style="charles",
         savefig="candlestick.png")

With Moving Averages

# Add 20 and 50 day moving averages
mpf.plot(data, type="candle", volume=True,
         mav=(20, 50),
         title="AAPL with 20/50 SMA",
         style="nightclouds",
         figsize=(14, 8),
         savefig="candlestick_sma.png")

Developer Essentials

As an Amazon Associate we may earn from qualifying purchases.