lightweight-charts-python
lightweight-charts-python copied to clipboard
[BUG] Trendline not working for arbitary timeframe
Expected Behavior
Trend line should appear for all timeframe
Current Behaviour
A vertical ine is shown instead of trend line (The trend_line is not working rather than working for some specific timeframe)
Reproducible Example
import pandas as pd
from lightweight_charts import Chart
import numpy as np
size = 1000
start_time = '2024-06-03 16:30:00'
num_periods = size
interval = '18min'#==> trend line works if it is '1min'/'2min'/../'18min' etc.
dates = pd.date_range(start=start_time, periods=num_periods, freq=interval)
np.random.seed(456)
# Generate random OHLC data
open_prices = np.random.uniform(low=1000, high=1500, size=size)
high_prices = open_prices + np.random.uniform(low=0, high=15, size=size)
low_prices = open_prices - np.random.uniform(low=0, high=15, size=size)
close_prices = np.random.uniform(low=low_prices, high=high_prices)
# Create a DataFrame
ohlc_data = pd.DataFrame({
'time': dates,
'open': open_prices,
'high': high_prices,
'low': low_prices,
'close': close_prices
})
ohlc_data.set_index('time',inplace=True)
chart = Chart()
chart.set(ohlc_data)
chart.trend_line(start_time = ohlc_data.index[0], start_value = ohlc_data .close.min(),
end_time=ohlc_data.index[50], end_value =ohlc_data .close.max(), line_color='blue', width=5, style='solid',round=True)
chart.show(block=True)
Environment
- OS:Ubuntu
- Library:
I have a similar problem with the drawing tools. In 1m and 5m the drawings don't render well when you upload to HTF the drawings end up in the left corner of the screen. The trend line becomes a vertical line. I thought it was a code error on my part but it seems to be rendering problems.
possible fix - https://github.com/louisnw01/lightweight-charts-python/issues/498#issuecomment-2642779469