Skip to content

Instantly share code, notes, and snippets.

@ChadThackray
Created June 21, 2024 07:26
Show Gist options
  • Save ChadThackray/7e0dd249bbc547b58d2695f6ee6aeadf to your computer and use it in GitHub Desktop.
Save ChadThackray/7e0dd249bbc547b58d2695f6ee6aeadf to your computer and use it in GitHub Desktop.
Candlestick charts in python from scratch with Plotly
# Licensed under the MIT License. See comment below for full licence information.
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv("Kraken_BTCUSD_d.csv")
df = df.iloc[::-1]
df['date'] = pd.to_datetime(df['date'])
df['20wma'] = df['close'].rolling(window = 140).mean()
fig = go.Figure(data=[go.Candlestick(x=df['date'],
open=df['open'], high=df['high'],
low=df['low'], close=df['close'])],
)
fig.add_trace(
go.Scatter(
x=df['date'],
y=df['20wma'],
line=dict(color="#e0e0e0"),
name = "20-week MA"
))
fig.update_layout(xaxis_rangeslider_visible=False, template="plotly_dark")
fig.update_layout(yaxis_title = "Bitcoin price (USD)", xaxis_title = "Date")
fig.update_yaxes(type="log")
fig.show()
@ChadThackray
Copy link
Author

Copyright 2021 Chad Thackray

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ChadThackray
Copy link
Author

Kraken data is no longer available but you can get bitstamp data from the same source:
https://www.cryptodatadownload.com/data/bitstamp/

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