LightweightChartsIOS icon indicating copy to clipboard operation
LightweightChartsIOS copied to clipboard

How do we create a candles/volumes chart?

Open johnqh opened this issue 2 years ago • 3 comments

I have successfully overlaid candles with an area chart, so it is probably possible to overlay candles with volume (bar) chart. Howe er, they are on the same pricing scale, both from the same 0 line for y axis. A proper candle/volume chart would have volumes at the bottom, and then candles on top with fixed area. They have independent y scales.

Would appreciate to know if it is possible and have a sample chart in the Example app.

johnqh avatar Feb 21 '23 18:02 johnqh

Hi @johnqh may I please know did you figure it out? thanks

wenweih avatar Jun 19 '23 06:06 wenweih

The solution is to apply different priceScaleId for xxxSeriesOptions.

Below is my sample setting for the chart.

let options = CandlestickSeriesOptions(
    priceScaleId: "1",
    priceLineSource: .lastVisible,
    priceLineColor: "rgba(0, 0, 0, 0.5)",
    upColor: "#fff",
    downColor: "rgba(0, 0, 0, 0.8)",
    borderUpColor: "rgba(0, 0, 0, 0.8)",
    borderDownColor: "rgba(0, 0, 0, 0.8)",
    wickUpColor: "rgba(0, 0, 0, 0.8)",
    wickDownColor: "rgba(0, 0, 0, 0.8)"
)

let series = chart.addCandlestickSeries(options: options)
series.setData(data: candlestickData)

...
let volumeSeriesOptions = HistogramSeriesOptions(
    lastValueVisible: false,
    priceScaleId: "2",
    priceLineVisible: false,
    priceFormat: .builtIn(BuiltInPriceFormat(type: .volume, precision: nil, minMove: nil)),
    color: "#26a69a"
)
let volumeSeries = chart.addHistogramSeries(options: volumeSeriesOptions)
volumeSeries.priceScale().applyOptions(
    options: PriceScaleOptions(
        scaleMargins: PriceScaleMargins(
            top: 0.85,
            bottom: 0
        )
    )
)
image

wenweih avatar Jun 19 '23 07:06 wenweih

@wenweih Are the lines in this chart MA lines? How did you achieve it?

image

ildream avatar Jul 14 '23 09:07 ildream