By:Rick Dobson || Related Tips: > Reporting Services Charts
ProblemOur startup stock advisory firm wants to leverage its SQL Server high-low-open-close stock price database by offering Candlestick charts to clients and prospects. Please provide some easy-to-follow examples about how to implement this capability.
SolutionmssqlTips.com includes several articles demonstrating how to download and build a SQL Server stock price database ( Using SQL Server Data Analysis for Stock Trading Strategies , SQL Server Data Mining Strategies for Stock Buy and Sell Recommendations , Pass Historical Data for Stocks from Google Finance to SQL Server ). The prior tips all included coverage of how to populate a high-low-open-close stock price database. Candlestick charts are a frequently used financial analysis tool for displaying high-low-open-close stock price series.
This tip drills down into SQL Server Reporting Services (SSRS) for displaying high-low-open-close stock price series. The tip shows and describes in a step-by-step fashion SSRS user interfaces for creating Candlestick charts. You will also learn how to copy a chart file and then modify the copy within an SSRS project. Three charts are created for a stock from the stock price database created in a prior MSSQLTips.com article ( Pass Historical Data for Stocks from Google Finance to SQL Server ).
Step-by-step instructions for creating your first Candlestick chartIn order to create a Candlestick chart with SSRS, you can first create a SSRS Report Server Project and give the project a name, such as MSSQLTips_EOD_StockPrice_CandleSticks.
Next, you need to add a new a Report item and give the item a name. The following screen shot shows the assignment of the name BasicCandleStick to a report item in the MSSQLTips_EOD_StockPrice_CandleSticks SSRS project. Notice that the report item has an .rdl file type. This is the type of file that SSRS uses to store the settings associated with a report item. As you make selections through the SSRS UI, the .rdl file gets populated with settings that match your selections.

Candlestick charts display a lot of details, and you may therefore find it useful to enlarge the default size of the report item window so the details are easy to view. Next, choose to insert a Chart object within the report. You can designate a Candlestick chart by choosing a Range chart type and then selecting a Candlestick type of Range chart. The following screen shot shows this selection.

After selecting a Candlestick type of chart, SSRS prompts you to designate a data source and query for the chart. Initially, you need to choose between using a shared data source or an embedded data source for the chart. For the sample charts in this tip, we use embedded data sources.
The core essence of a data source is a SQL Server instance name and a database name within the instance. You can choose to edit the connection properties for a new data source and then specify a server instance name, a database name on the instance and login credentials that will connect to the database on the database server. It is a good practice to click the Test Connection button within the Connection Properties dialog box before going on to specify a query.
The following screen shot shows the Data Source Properties dialog after a server and database were selected for the BasicCandlestick chart. The Data Source name, which is covered for security reasons, shows the name of the server instance. The Initial Catalog name points to the name of the database on the server. The stocks_for_mining database is the name of the database created in a prior tip that contains a table with daily historical end-of-day stock price data that are suitable for display in a Candlestick chart.

The next screen shot presents a Query Designer view of a query and an excerpt from its results set used as a resource by the BasicCandlestick chart. The FROM clause designates as its source a table named stocks_symbol_ohlcv in the stocks_for_mining database. This table contains standard end-of-day data for a collection of stock symbols; each symbol references the stock for a different company. In addition to SYMBOL, column values are for date and several different daily stock performance indicators, such as high price, low price, open price, close price, and volume. A WHERE clause selects data exclusively for the ULTA stock symbol, which is for a salon, cosmetics, and fragrance corporation.
The Candlestick chart represents the high, low, open, and close prices for each day for the ulta stock symbol. Normally, a Candlestick chart displays the price data for a symbol over a selected date range, such as from April 7, 2016 through June 30, 2016. This range is also specified in the query's WHERE clause.
The results pane shows the first five rows of the query's result set. Additionally, the first, second, and fifth rows are highlighted.
The first row has the same open and close prices. The second row has a higher open price than close price. The fifth row has a higher close price than open price.The values of the open price relative to the close price affects the appearance of the candle in a Candlestick chart. Therefore, the candle for any day can quickly depict whether a stock price went up, down, or stayed the same on any given day.

After specifying your embedded data source and dataset, you can select your chart and be prompted with a Chart Data window. Click the plus sign (+) in the window and select High. Then, enter Sum(high) as the first selection in the Chart Data window. The next screen shot shows the final screen after making these selections.

Next, right-click any Candlestick bar in the Design View tab for the chart and choose Series Properties. This choice opens the Series Properties dialog box, which you can use to specify the low, open, and close values for each candlestick in a Candlestick chart. The high, low, open, and close values plot along the vertical axis of a Candlestick chart. Additionally, you can specify date as the column for category values along the horizontal axis. It is often helpful to designate a Tooltip value for a Candlestick value to show a value for any candlestick in a Candlestick chart. For the BasicCandleStick chart, close price values are designated as Tooltip values. While volume is in the result set because it is routinely reported with other stock performance indicators, the volume indicator does not appear directly within a Candlestick chart. The following screen shot shows these selections in the Series Properties dialog box for the BasicCandleStick chart.
