Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/1_setting_data/setting_data.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import pandas as pd
from lightweight_charts import Chart
import os

if __name__ == '__main__':
if __name__ == "__main__":
chart = Chart()

path = os.path.join(os.path.dirname(__file__), "ohlcv.csv")

# Columns: time | open | high | low | close | volume
df = pd.read_csv('ohlcv.csv')
df = pd.read_csv(path)
chart.set(df)

chart.show(block=True)
2,982 changes: 2,982 additions & 0 deletions examples/7_panes/ohlcv.csv

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions examples/7_panes/pane.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import pandas as pd

from lightweight_charts import Chart


def calculate_sma(df, period: int = 50):
return pd.DataFrame(
{"time": df["date"], f"SMA {period}": df["close"].rolling(window=period).mean()}
).dropna()


def calculate_macd(df, short_period=12, long_period=26, signal_period=9):
short_ema = df["close"].ewm(span=short_period, adjust=False).mean()
long_ema = df["close"].ewm(span=long_period, adjust=False).mean()
macd = short_ema - long_ema
signal = macd.ewm(span=signal_period, adjust=False).mean()
histogram = macd - signal
return pd.DataFrame(
{
"time": df["date"],
"MACD": macd,
"Signal": signal,
"Histogram": histogram,
}
).dropna()


if __name__ == "__main__":
chart = Chart(inner_height=1)
chart.legend(visible=True)

chart.watermark("Main")

path = os.path.join(os.path.dirname(__file__), "ohlcv.csv")

df = pd.read_csv(path)

df = df.head(10)

chart.set(df)

sma_data = calculate_sma(df, period=5)

line = chart.create_line("SMA 5")
line.set(sma_data)

# Subchart with MACD

macd_data = calculate_macd(df)

histogram = chart.create_histogram("MACD", pane_index=1)
histogram.set(macd_data[["time", "MACD", "Signal", "Histogram"]])

chart.show(block=True)
Binary file added examples/7_panes/panes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading