Created
March 11, 2022 14:37
-
-
Save rohithteja/d098316b7b81caf6c021181b6b2fe666 to your computer and use it in GitHub Desktop.
Candle stick chart Plotly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yfinance as yf | |
import pandas as pd | |
import plotly.graph_objs as go | |
# download 5 year crypto prices from Yahoo Finance | |
df = yf.download(tickers='BTC-USD', period = '5y', interval = '1d') | |
# compute moving averages | |
df['MA100'] = df.Close.rolling(100).mean() | |
df['MA50'] = df.Close.rolling(50).mean() | |
df['MA20'] = df.Close.rolling(20).mean() | |
# Plotly candlestick chart | |
fig = go.Figure(data= | |
[go.Candlestick(x=df.index, | |
open=df.Open, | |
high=df.High, | |
low=df.Low, | |
close=df.Close, | |
name=f'{select_token}'), | |
go.Scatter(x=df.index, y=df.MA20, | |
line=dict(color='yellow',width=1),name='MA20'), | |
go.Scatter(x=df.index, y=df.MA50, | |
line=dict(color='green',width=1),name='MA50'), | |
go.Scatter(x=df.index, y=df.MA100, | |
line=dict(color='red',width=1),name='MA100')]) | |
fig.update_layout(go.Layout(xaxis = {'showgrid': False}, | |
yaxis = {'showgrid': False}), | |
title=f'{dic1[select_token]} Price Fluctuation with Moving Averages', | |
yaxis_title=f'Price ({select_fiat})', | |
xaxis_rangeslider_visible=False) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment