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

How to delete indicator

Open Lsgo opened this issue 5 months ago • 1 comments

Question

I have added an indicator selection item on the interface, and clicking on the indicator will continuously add it. How can I delete the added indicator

Image

Code example

def on_indicators_selection(chart):
    print(f'Indicators selection: {chart.topbar["indicators"].value}')
    if chart.topbar["indicators"].value == 'MA':
 
        list_ma = [5,10,20,60,120]
        list_color = ['rgba(121,146,177,0.8)','rgba(255,255,11,0.8)','rgba(255,128,255,0.8)','rgba(0,230,0 ,0.8)','rgba(0,178,240,0.8)']
        sma_data = calculate_sma(df,list_ma)
        line = {}
       
        for index, value in enumerate(list_ma):
            line[value] = chart.create_line(f'SMA {value}',color=list_color[index])
            line[value].set(sma_data[['time',f'SMA {value}']])
    elif chart.topbar["indicators"].value == 'BOLL':
        boll_data = calculate_boll(df)
        line_up = chart.create_line('BOLL_UP',color='rgba(121,146,177,0.8)',style='dotted')
        line_up.set(boll_data[['time','BOLL_UP']])
        line_down = chart.create_line('BOLL_DOWN',color='rgba(121,146,177,0.8)',style='dotted')
        line_down.set(boll_data[['time','BOLL_DOWN']])
        line_boll = chart.create_line('BOLL',color='rgba(255,128,255,0.8)')
        line_boll.set(boll_data[['time','BOLL']])
        chart.set(boll_data)
    elif chart.topbar["indicators"].value == 'CL':
        pass

Lsgo avatar Jul 29 '25 16:07 Lsgo

I've tried a different approach: using line.set(None) and setting div.style.display = 'none'. However, it would be even better if there's a more straightforward way to directly remove the indicator.

Lsgo avatar Jul 30 '25 14:07 Lsgo