Plot Candlestick Chart using mplfinance module in Python
Candlestick chart are also known as a Japanese chart. These are widely used for technical analysis in trading as they visualize the price size within a period. They have four points Open, High, Low, Close (OHLC). Candlestick charts can be created in python using a matplotlib module called mplfinance.
pip install mplfinance
This function is used to plot Candlestick charts.
Syntax: mplfinance.candlestick_ohlc(ax, quotes, width=0.2, colorup=’k’, colordown=’r’, alpha=1.0)
- ax: An Axes instance to plot to.
- quotes: Aequence of (time, open, high, low, close, …) sequences.
- width: Fraction of a day for the rectangle width.
- colorup: The color of the rectangle where close >= open.
- colordown: The color of the rectangle where close < open.
- alpha: (float) The rectangle alpha level.
Returns: returns (lines, patches) where lines are a list of lines added and patches is a list of the rectangle patches added.
To plot the chart, we will take data from NSE for the period 01-07-2020 to 15-07-2020, the data is available for download in a csv file, or can be downloaded from here. For this example, it is saved as ‘data.csv’.
We will use the pandas library to extract the data for plotting from data.csv.
Below is the implementation:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course