Skip to content
Open
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
4 changes: 2 additions & 2 deletions docs/source/reference/abstract_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ___



```{py:method} create_line(name: str, color: COLOR, style: LINE_STYLE, width: int, price_line: bool, price_label: bool) -> Line
```{py:method} create_line(name: str, color: COLOR, style: LINE_STYLE, type: LINE_TYPE, width: int, price_line: bool, price_label: bool) -> Line

Creates and returns a Line object, representing a `LineSeries` object in Lightweight Charts and can be used to create indicators. As well as the methods described below, the `Line` object also has access to:

Expand Down Expand Up @@ -89,7 +89,7 @@ ___



```{py:method} trend_line(start_time: str | datetime, start_value: NUM, end_time: str | datetime, end_value: NUM, color: COLOR, width: int, style: LINE_STYLE, round: bool) -> Line
```{py:method} trend_line(start_time: str | datetime, start_value: NUM, end_time: str | datetime, end_value: NUM, line_color: COLOR, width: int, style: LINE_STYLE, round: bool) -> Line

Creates a trend line, drawn from the first point (`start_time`, `start_value`) to the last point (`end_time`, `end_value`).

Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/line.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `Line`


````{py:class} Line(name: str, color: COLOR, style: LINE_STYLE, width: int, price_line: bool, price_label: bool, price_scale_id: str)
````{py:class} Line(name: str, color: COLOR, style: LINE_STYLE, type: LINE_TYPE, width: int, price_line: bool, price_label: bool, price_scale_id: str)

The `Line` object represents a `LineSeries` object in Lightweight Charts and can be used to create indicators. As well as the methods described below, the `Line` object also has access to:

Expand Down
3 changes: 3 additions & 0 deletions docs/source/reference/typing.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Throughout the library, colors should be given as either rgb (`rgb(100, 100, 100
```{py:class} LINE_STYLE(Literal['solid', 'dotted', 'dashed', 'large_dashed', 'sparse_dotted'])
```

```{py:class} LINE_TYPE(Literal['simple', 'with_steps', 'curved'])
```

```{py:class} MARKER_POSITION(Literal['above', 'below', 'inside'])
```

Expand Down
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