Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Add Volume to Candlestick chart

Is there any posibility to add Volume(trades) to Candlestick chart?
Thanks.

Yes it is possible. Here you go my friend :wink: this is my own code.

#import the libraries
import plotly.subplots as ms
import plotly.graph_objects as go
import pandas as pd

#Load the stock data
df = pd.read_csv(‘20180507-table_blnk.csv’)
#Set the index
df = df.set_index(pd.DatetimeIndex(df[‘Time’].values))

Make Subplot of 2 rows to plot 2 graphs sharing the x axis

fig = ms.make_subplots(rows=2,
cols=1,
shared_xaxes=True,
vertical_spacing=0.02)

Add Candlstick Chart to Row 1 of subplot

fig.add_trace(go.Candlestick(x = df.index,
low = df[‘Low’],
high = df[‘High’],
close = df[‘Close’],
open = df[‘Open’],
increasing_line_color = ‘green’,
decreasing_line_color = ‘red’),
row=1,
col=1)

#Add Volume Chart to Row 2 of subplot
fig.add_trace(go.Bar(x=df.index,
y=df[‘Volume’]),
row=2,
col=1)

#Update Price Figure layout
fig.update_layout(title = ‘Interactive CandleStick & Volume Chart’,
yaxis1_title = ‘Stock Price ($)’,
yaxis2_title = ‘Volume (M)’,
xaxis2_title = ‘Time’,
xaxis1_rangeslider_visible = False,
xaxis2_rangeslider_visible = True)