Tuesday, February 5, 2013

Candlestick and OHLC Charting With .Net Charting Library


Advertisement

Advertisement
The .Net Framework's most recent versions (4 and 4.5) come with a fairly useful charting library for developing Windows Forms applications. It is really easy to put together a charting application using the System.Windows.Forms.DataVisualization.Charting namespace and the .Net Chart class.

Most of the chart types are fairly straightforward, but the financial chart types (point and figure, candlestick, and OHLC) are a little less intuitive because they require multiple Y values per DataPoint and Microsoft has done a poor job documenting the right order to add these. I suppose that this post could fill that gap.

For the OHLC and Cadlestick chart types, the right order to add the open, high, low, and close values to a DataPoint is the following: high, low, close, open. See the following code sample where I plot a set of trading day values for a particular equity:


        private void RefreshChart()
        {
            //Clear the points that are currently plotted
            CandlestickChart.Series["OHLCSeries"].Points.Clear();

            //Plot a subset of points from our time series
            for (int i = start_i; i <= end_i; i++)
            {
                CandlestickChart.Series["OHLCSeries"].Points.AddY(
                    current_equity[i].high,
                    current_equity[i].low,
                    current_equity[i].close,
                    current_equity[i].open);
            }

        } --> 

In the end, you get a correct Candlestick Chart (in my case, I'm building an application to help my trading skills):

No comments:

Post a Comment