Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yongghongg/874eb50be61c8971786939bb8f5eca2e to your computer and use it in GitHub Desktop.
Save yongghongg/874eb50be61c8971786939bb8f5eca2e to your computer and use it in GitHub Desktop.
# we are using mplfinance to help us visualize the indicator
import mplfinance as mpf
# to make the visualization better by only taking the last 100 rows of data
df = df[-100:]
# extract only ['Open', 'High', 'Close', 'Low'] from df
ohcl = df[['Open', 'High', 'Close', 'Low']]
# add colors for the 'value bar'
colors = []
for ind, val in enumerate(df['value']):
if val >= 0:
color = 'green'
if val > df['value'][ind-1]:
color = 'lime'
else:
color = 'maroon'
if val < df['value'][ind-1]:
color='red'
colors.append(color)
# add 2 subplots: 1. bars, 2. crosses
apds = [mpf.make_addplot(df['value'], panel=1, type='bar', color=colors, alpha=0.8, secondary_y=False),
mpf.make_addplot([0] * len(df), panel=1, type='scatter', marker='x', markersize=50, color=['gray' if s else 'black' for s in df['squeeze_off']], secondary_y=False)]
# plot ohcl with subplots
fig, axes = mpf.plot(ohcl,
volume_panel = 2,
figratio=(2,1),
figscale=1,
type='candle',
addplot=apds,
returnfig=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment