NEW FEATURE: Trendlines, Rays and the Toolbox
- Added `trend_line` and `ray_line` to the Common Methods.
- Added the `toolbox` parameter to chart declaration. This allows horizontal lines, trend lines and rays to be drawn on the chart using hotkeys and buttons.
- cmd-Z will delete the last drawing.
- Drawings can be moved by clicking and dragging.
- Added the `render_drawings` parameter to `set`, which will keep and re-render the drawings displayed on the chart (useful for multiple timeframes!)
Horizontal Lines
- The `horizontal_line` method now returns a HorizontalLine object, containing the methods `update` and `delete`.
- Added the `interactive` parameter to `horizontal_line`, allowing for callbacks to be emitted to the `on_horizontal_line_move` callback method when the line is dragged to a new price (stop losses, limit orders, etc.).
Enhancements:
- added the `precision` method to the Common Methods, allowing for the number of decimal places shown on the price scale to be declared.
- Lines displayed on legends now have toggle switches, allowing for their visibility to be controlled directly within the chart window.
- when using `set`, the column names can now be capitalised, and the `date` column can be the index.
Changes:
- Merged the `title` method into the `price_line` method.
This commit is contained in:
28
README.md
28
README.md
@ -3,7 +3,7 @@
|
||||
# lightweight-charts-python
|
||||
|
||||
[](https://pypi.org/project/lightweight-charts/)
|
||||
[](https://python.org "Go to Python homepage")
|
||||
[](https://python.org "Go to Python homepage")
|
||||
[](https://github.com/louisnw01/lightweight-charts-python/blob/main/LICENSE)
|
||||
[](https://lightweight-charts-python.readthedocs.io/en/latest/docs.html)
|
||||
|
||||
@ -24,10 +24,12 @@ ___
|
||||
1. Simple and easy to use.
|
||||
2. Blocking or non-blocking GUI.
|
||||
3. Streamlined for live data, with methods for updating directly from tick data.
|
||||
4. __Supports:__ Jupyter Notebooks, PyQt, wxPython, Streamlit, and asyncio.
|
||||
5. [Callbacks](https://lightweight-charts-python.readthedocs.io/en/latest/docs.html#callbacks) allowing for timeframe (1min, 5min, 30min etc.) selectors, searching, and more.
|
||||
6. Multi-Pane Charts using the [`SubChart`](https://lightweight-charts-python.readthedocs.io/en/latest/docs.html#subchart).
|
||||
4. Multi-Pane Charts using the [`SubChart`](https://lightweight-charts-python.readthedocs.io/en/latest/docs.html#subchart).
|
||||
5. The Toolbox, allowing for trendlines, rays and horizontal lines to be drawn directly onto charts.
|
||||
6. [Callbacks](https://lightweight-charts-python.readthedocs.io/en/latest/docs.html#callbacks) allowing for timeframe (1min, 5min, 30min etc.) selectors, searching, and more.
|
||||
7. Direct integration of market data through [Polygon.io's](https://polygon.io) market data API.
|
||||
|
||||
__Supports:__ Jupyter Notebooks, PyQt, wxPython, Streamlit, and asyncio.
|
||||
___
|
||||
|
||||
### 1. Display data from a csv:
|
||||
@ -129,19 +131,20 @@ def calculate_sma(data: pd.DataFrame, period: int = 50):
|
||||
result = []
|
||||
for i in range(period - 1, len(data)):
|
||||
val = avg(data.iloc[i - period + 1:i])
|
||||
result.append({'time': data.iloc[i]['date'], 'value': val})
|
||||
result.append({'time': data.iloc[i]['date'], f'SMA {period}': val})
|
||||
return pd.DataFrame(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
chart = Chart()
|
||||
|
||||
chart.legend(visible=True)
|
||||
|
||||
df = pd.read_csv('ohlcv.csv')
|
||||
chart.set(df)
|
||||
|
||||
line = chart.create_line()
|
||||
sma_data = calculate_sma(df)
|
||||
line._set(sma_data)
|
||||
sma_data = calculate_sma(df, period=50)
|
||||
line.set(sma_data, name='SMA 50')
|
||||
|
||||
chart.show(block=True)
|
||||
|
||||
@ -218,12 +221,15 @@ class API:
|
||||
if new_data.empty:
|
||||
return
|
||||
self.chart.set(new_data)
|
||||
|
||||
async def on_horizontal_line_move(self, line_id, price):
|
||||
print(f'Horizontal line moved to: {price}')
|
||||
|
||||
|
||||
async def main():
|
||||
api = API()
|
||||
|
||||
chart = Chart(api=api, topbar=True, searchbox=True)
|
||||
chart = Chart(api=api, topbar=True, searchbox=True, toolbox=True)
|
||||
chart.legend(True)
|
||||
|
||||
chart.topbar.textbox('corner', 'TSLA')
|
||||
@ -231,6 +237,8 @@ async def main():
|
||||
|
||||
df = get_bar_data('TSLA', '5min')
|
||||
chart.set(df)
|
||||
|
||||
chart.horizontal_line(200, interactive=True)
|
||||
|
||||
await chart.show_async(block=True)
|
||||
|
||||
@ -245,6 +253,8 @@ ___
|
||||
<div align="center">
|
||||
|
||||
[](https://lightweight-charts-python.readthedocs.io/en/latest/docs.html)
|
||||
|
||||
Inquiries: [shaders_worker_0e@icloud.com](mailto:shaders_worker_0e@icloud.com)
|
||||
___
|
||||
|
||||
_This package is an independent creation and has not been endorsed, sponsored, or approved by TradingView. The author of this package does not have any official relationship with TradingView, and the package does not represent the views or opinions of TradingView._
|
||||
|
||||
Reference in New Issue
Block a user