Skip to content

Instantly share code, notes, and snippets.

@SajidLhessani
Last active August 1, 2022 17:19
Show Gist options
  • Save SajidLhessani/8d6ab7130874337044116bb566782727 to your computer and use it in GitHub Desktop.
Save SajidLhessani/8d6ab7130874337044116bb566782727 to your computer and use it in GitHub Desktop.
# Raw Package
import numpy as np
import pandas as pd
#Data Source
import yfinance as yf
#Data viz
import plotly.graph_objs as go
#Importing market data
data = yf.download(tickers='BTC-USD',period = '8d', interval = '90m')
#Adding Moving average calculated field
data['MA5'] = data['Close'].rolling(5).mean()
data['MA20'] = data['Close'].rolling(20).mean()
#declare figure
fig = go.Figure()
#Candlestick
fig.add_trace(go.Candlestick(x=data.index,
open=data['Open'],
high=data['High'],
low=data['Low'],
close=data['Close'], name = 'market data'))
#Add Moving average on the graph
fig.add_trace(go.Scatter(x=data.index, y= data['MA20'],line=dict(color='blue', width=1.5), name = 'Long Term MA'))
fig.add_trace(go.Scatter(x=data.index, y= data['MA5'],line=dict(color='orange', width=1.5), name = 'Short Term MA'))
#Updating X axis and graph
# X-Axes
fig.update_xaxes(
rangeslider_visible=True,
rangeselector=dict(
buttons=list([
dict(count=3, label="3d", step="days", stepmode="backward"),
dict(count=5, label="5d", step="days", stepmode="backward"),
dict(count=7, label="WTD", step="days", stepmode="todate"),
dict(step="all")
])
)
)
#Show
fig.show()
@jsgaston
Copy link

hi, i have a problem ... figure is not shown . why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment