Trading Bitcoin using Candlesticks

Candlestick pattern detection in Python using Pandas

Michael Whittle
Trading Data Analysis
6 min readJan 24, 2021

--

This article will cover how to programmatically detect common candlesticks in trading and how to plot them on a graph. I’ll be using Bitcoin data retrieved via the Coinbase Pro API.

The first step is we need to create ourselves a Pandas DataFrame with the trading data. I’ve actually done this already and made it really easy for you. You can use the code from my trading bot repo.

Let’s get started…

First, we need to import the following libraries.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from models.CoinbasePro import CoinbasePro

NumPy is a mathematical library used extensively in data science, Matplotlib is a graphing and plotting library also used extensively in data science. CoinbasePro is my object model which you can find in my trading bot repo.

Next, we want to retrieve the data from the Coinbase Pro API and create our Pandas DataFrame. I’ll be retrieving the BTC-GBP market using 1 hour intervals.

coinbasepro = CoinbasePro('BTC-GBP', 3600)
df = coinbasepro.getDataFrame()

--

--

Solution Architect — CCIE R&S #24223 | Full-Stack / Blockchain / Web3 Developer | Security Specialist | PyCryptoBot Creator