Pre loader

Candlestick Chart Coloring

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
0
0

Hi,

According to the documentation, in FastCandlestickRenderableSeries

StrokeUp and FillUp styles are applied to bars with Close > Open, and StrokeDown and FillDown to those that have Open <= Close respectively.

I would like to ask is there any method to achieve the following:

The candlestick are green in color when Today Close >= Previous Close and red in color when Today Close < Previous Close

Thanks.

Version
v1.2.1
  • You must to post comments
Great Answer
1
0

Hi Ray,

Unfortunately there is no built-in functionality which allows to do this out of the box. But you can try to use PaletteProvider API and override colors for candles on your own. In this case you’ll need to iterate over points in render pass data and based on its content set desired colors.

I quickly tried to create a prototype of such palette provider so now you have some code to start from:

public class CandlePaletteProvider extends PaletteProviderBase<FastCandlestickRenderableSeries> implements IStrokePaletteProvider, IFillPaletteProvider {

    private final IntegerValues colors = new IntegerValues();

    public CandlePaletteProvider() {
        super(FastCandlestickRenderableSeries.class);
    }

    @Override
    public void update() {
        final OhlcRenderPassData currentRenderPassData = ((FastCandlestickRenderableSeries<?, ?>) renderableSeries).getCurrentRenderPassData();

        final int pointsCount = currentRenderPassData.pointsCount();
        colors.setSize(pointsCount);

        final int[] colorsItems = colors.getItemsArray();
        final double[] closeValues = currentRenderPassData.closeValues.getItemsArray();

        colorsItems[0] = Color.GREEN;
        for (int i = 1; i < pointsCount; i++) {
            colorsItems[i] = closeValues[i] >= closeValues[i-1] ? Color.GREEN : Color.RED;
        }
    }

    @Override
    public final IntegerValues getFillColors() {
        return colors;
    }

    @Override
    public final IntegerValues getStrokeColors() {
        return colors;
    }
}

Hope this will help you!


In v2.x to make this code working you need to replace this line:

final OhlcRenderPassData currentRenderPassData = ((FastCandlestickRenderableSeries<?, ?>) renderableSeries).getCurrentRenderPassData();

on this line (in v2.x we removed generic params from RenderableSeries so you need to cast render pass data):

final OhlcRenderPassData currentRenderPassData = (OhlcRenderPassData) renderableSeries.getCurrentRenderPassData();

Best regards,
Yura

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies