How to use Bar/OHLC instead of Candlesticks?
Question
The TradingView library supports a few different styles. Can I also use them in the Python implementation? I want to use the OHLC aka Bar instead of the Candlestick style. I checked the docs, but couldn't find anything.
Not supported yet, but you can find it's implementation here https://github.com/EsIstJosh/lightweight-charts-python/tree/main
While it hasn't been officially implemented yet here, you can add it pretty easily if you want to by replicating the candlestick series' implementation inside of abstract.py and the other series instantiation methods within ./src/general/handler.ts and adjusting it to use bars...
Alternatively, feel free to check out my fork of the project, which includes support for both Bar and Area series. I extended the system using the approach described above, and also introduced a Custom OHLC series that can be configured to render in a variety of shapes—including traditional bar plots
Alternatively, feel free to check out my fork of the project, which includes support for both Bar and Area series.
Is your library intended to be used as drop in replacement? I built my application with a lot of subplots, table and hotkeys. Anything I need to to take care for migration?
It is however you will likely run into issues if you try to just switch to my version because i've updated the lightweight-charts library to version 5, not to mention all the other little changes that were made along the way. I haven't really used the tables or hotkeys so I'm not sure if it still works as intended. I would guess it'd be less of a headache to just extract and implement the sections relevant to your use case.
@debegr92 I would also recommend migrating to v5 first using this https://github.com/louisnw01/lightweight-charts-python/pull/524. New Panes API is a bit better for subcharts than current implementation I think.
Not supported yet, but you can find it's implementation here
Sadly the CustomCandle is nor working together with the tick update. So I stick to the normal Candlestick chart.
try to just switch to my version because i've updated the lightweight-charts library to version 5, not to mention all the other little changes that were made along the way
I tried your version a bit. Just confused about the features. Is the new Panes API implemented?
@debegr92 Here is a possible approach
python
self.chart.switch_chart_type("bar")
self.chart.set(self.df, keep_drawings=True)
JS -> abstract
def switch_chart_type(self, type: str):
"""
Switches the chart type to either 'candle' or 'bar'.
"""
self.run_script(f"{self.id}.switchSeriesType('{type}')")
JS -> bundle.js
createSeries(chartType) {
if (chartType === "candle") {
return this.createCandlestickSeries();
} else if (chartType === "bar") {
return this.createBarSeries();
} else {
throw new Error("Invalid series type specified: " + this.seriesType);
}
}
createBarSeries() {
const settings = this.settings(); // Call settings method
// Fallback colors if settings or nested properties are missing
const defaultUpColor = "rgba(39, 157, 130, 100)";
const defaultDownColor = "rgba(200, 97, 100, 100)";
const t = settings?.chart?.candle_style?.up_color ?? defaultUpColor;
const e = settings?.chart?.candle_style?.down_color ?? defaultDownColor;
const i = this.chart.addBarSeries({
upColor: t,
borderUpColor: t,
wickUpColor: t,
downColor: e,
borderDownColor: e,
wickDownColor: e,
});
i.priceScale().applyOptions({
scaleMargins: {
top: 0.2,
bottom: 0.2,
},
});
return i;
}