louisnw01 / lightweight-charts-python

Python framework for TradingView's Lightweight Charts JavaScript library.
MIT License
1.15k stars 213 forks source link

[BUG] Trendline not working for arbitary timeframe #471

Open soumenhalder opened 2 weeks ago

soumenhalder commented 2 weeks ago

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:
cilindro5432 commented 6 days ago

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.