lightweight-charts-python icon indicating copy to clipboard operation
lightweight-charts-python copied to clipboard

subchart sync not working when zooming in and out or full screen change or trading time change - live data updates

Open esteban2006 opened this issue 1 year ago • 1 comments

Expected Behavior

as the user would zoom in or out in withing the main chart, the subchart should replicate the action mantaining the same position on the time scale, specially.

Current Behaviour

When zooming in or our or going full screen the subchart loose track of the current time scale and position

https://github.com/user-attachments/assets/6bda6e56-d528-4e6c-9a61-c2a165b03924

Reproducible Example

import pandas as pd
from lightweight_charts import Chart

if __name__ == '__main__':
    chart = Chart(inner_width=1, inner_height=0.8)
    chart.time_scale(visible=False)

    chart2 = chart.create_subchart(width=1, height=0.2, sync=True)
    line = chart2.create_line()
    
    df = pd.read_csv('ohlcv.csv')
    df2 = pd.read_csv('rsi.csv')

    chart.set(df)
    line.set(df2)

    chart.show(block=True)

Environment

- OS: windows
- name='lightweight_charts', version='2.0.1',
- python ='3.1',

esteban2006 avatar Jul 27 '24 19:07 esteban2006

+1 Facing same issue here.

digital-stoic avatar Aug 13 '24 09:08 digital-stoic

How did you fix this ?

nithesh10 avatar Aug 19 '24 00:08 nithesh10

Hi all, FYI how I could fix in my case:

The issue was the number of X data points, that must be the same between the candles/lines of all charts and subcharts, regardless of the Xmin and Xmax after a fit().

digital-stoic avatar Aug 19 '24 07:08 digital-stoic

@digital-stoic could you share your solution ?

esteban2006 avatar Sep 14 '24 19:09 esteban2006

@esteban2006 : It's just a data quality thing, not code per se: Ensure that the number of data points on the X axis is the same between your chart and subcharts.

digital-stoic avatar Sep 15 '24 08:09 digital-stoic

Sync is based on the logical index of a datapoint, not the time. In your case, you need to pad the beggining of your indicator with empty values.

louisnw01 avatar Sep 28 '24 14:09 louisnw01