SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

0
0

Hi,

is it possible to have same colors on my volume chart based on OHLC chart (red Green)? One option I see is to create a dependency property, and bind to OHLC Series data source to my VolumePalletteProvider? Is there any pre-existing way, without requiring me to bind to OHLC Series source?

public class VolumePallettProvider : IStrokePaletteProvider, IFillPaletteProvider
{
    Color _sbC = Colors.LightPink;
    SolidColorBrush _sb = Brushes.Transparent;

    public void OnBeginSeriesDraw(IRenderableSeries series)
    {
        _sbC = (Color)ColorConverter.ConvertFromString("#FF713232");
        _sb = (SolidColorBrush)new BrushConverter().ConvertFromString("#FFB75252");
    }

    public Brush OverrideFillBrush(IRenderableSeries rSeries, int index, IPointMetadata metadata)
    {
        var series = rSeries.DataSeries as XyDataSeries<DateTime, double>;
        var value = null != series ? series.YValues[index] : 0;
        value = !Double.IsNaN(value) ? value : 0;
        if (value < 0)
            return _sb;
        return null;
    }

    public Color? OverrideStrokeColor(IRenderableSeries rSeries, int index, IPointMetadata metadata)
    {
        var series = rSeries.DataSeries as XyDataSeries<DateTime, double>;
        var value = null != series ? series.YValues[index] : 0;
        value = !Double.IsNaN(value) ? value : 0;
        if (value < 0)
            return _sbC;
        return null;
    }
}
Version
V6
  • You must to post comments
0
0

Yes you certainly can Vinay,

We blogged about this in the page Algorithmic Trading with SciChart. All you need to do is pass the OhlcDataSeries for the candlestick data to the VolumePaletteProvider and you can choose bar colours based off Open, High, Low and Close.

For example:

public class VolumePaletteProvider : IFillPaletteProvider, IStrokePaletteProvider
{
    private readonly OhlcDataSeries<DateTime, double> _priceSeries;
    private readonly Color _upWick;
    private readonly Color _downWick;
    private readonly Brush _upFill;
    private readonly Brush _downFill;
    private OhlcDataSeries<DateTime, double> _dataSeries;

    public VolumePaletteProvider(OhlcDataSeries<DateTime, double> priceSeries, Color upWick, Color downWick, Brush upFill, Brush downFill)
    {
        _priceSeries = priceSeries;
        _upWick = upWick;
        _downWick = downWick;
        _upFill = upFill;
        _downFill = downFill;
    }

    public void OnBeginSeriesDraw(IRenderableSeries rSeries)
    {
    }

    public Color? OverrideStrokeColor(IRenderableSeries rSeries, int index, IPointMetadata metadata)
    {
        var ohlcSeries = _priceSeries;
        if (ohlcSeries == null || ohlcSeries.Count == 0) return null;
        return ohlcSeries.CloseValues[index] >= ohlcSeries.OpenValues[index] ? _upWick : _downWick;
    }

    public Brush OverrideFillBrush(IRenderableSeries rSeries, int index, IPointMetadata metadata)
    {
        var ohlcSeries = _priceSeries;
        if (ohlcSeries == null || ohlcSeries.Count == 0) return null;
        return ohlcSeries.CloseValues[index] >= ohlcSeries.OpenValues[index] ? _upFill : _downFill;
    }
}

Then usage like this

        VolumeRenderableSeries.PaletteProvider = new VolumePaletteProvider(
                                                 MainPriceOhlcSeries,  // Pass in the price OhlcSeries. 
                                                Resources.UpColor.MakeTransparent(0.5),
                                                Resources.DownColor.MakeTransparent(0.5), 
                                                Resources.UpBrush.MakeTransparent(0.5), 
                                                Resources.DownBrush.MakeTransparent(0.5));

Assume above the VolumeRenderableSeries is type FastColumnRenderableSeries and is painting your volume. If you pass in the OhlcDataSeries for the main candelstick chart, then you can choose colours based on the Open and Close.

Hope this helps!

Best regards,
Andrew

  • You must to post comments
0
0

Thanks.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.