This post shows how to create the candlestick chart in Tableau. A candlestick chart is often used to show stock price performance. It shows the Open and Close prices as well as the High and Low. In addition the colour shows whether the price is up or down on the day.
A candlestick chart shows the Open, Close, High and Low price of a stock over a given period.
To build a candlestick chart in Tableau the first thing is to get some daily share price data. As I learnt Tableau while working at Homeaway.com for this exercise we will use their share price data.
The Nasdaq website has freely available daily stock data for the past 2 years.
The dataset is very simple. It contains the date, open price, close price, day high, day low and the volume. I added the ticker as well, although unnecessary when only looking at one stock.
To build the chart firstly we plot out the daily high and daily low values. Put the date field to the Columns shelf using the continuous Day or Exact Date setting. Next drag the High pill to the Rows and set it to AVG, therefore giving a line chart of the daily high values. Put the Low on the chart and set to AVG. This is now a line of daily highs and daily lows.
Hint: If you drag the Low pill to the Y axis, poorly circled in red, and drop it there, this will automatically show both lines on the same chart.
Build the candle wick
With a candlestick chart the high and low forms the candle wick. To create the wick first change the Date pill to be Discrete (blue).
To separate out each day put the Date field on the Detail shelf and set it to a dimension with MDY.
Also edit the Y axis, it doesn’t need to show the zero (right click on the axis, Edit Axis, uncheck the Include Zero box). Now there are many dots on the chart representing the daily highs and lows. Connect these dots to create the wick of the candle.
A simple calculated field completes the wick. Name the calculated field [Up or Down] and the formula is as follows:
IF AVG([Close]) > AVG([Open]) THEN “Up” ELSE “Down” END.
In other words if the close is greater then the open it is up otherwise it is down.
To complete the candle wicks of the candlestick chart put [Up or Down] on the Colour shelf. Change the colours to represent up and down. In this example the Up is blue and red is Down.
Build the candle body
Next build the candle body. This is based on the Open and Close price. A combination of Reference lines and formulae create the candle body. To begin we’ll create the candles for those that closed up after the days trading.
- Drag the Open and Close fields to the Detail shelf, and set both to AVG
- Create a new calculated field called Closed Up
- The formula for Closed Up is IF AVG([Close])>AVG([Open]) THEN AVG([Close]) END
- Drag Closed Up to the Detail shelf
- Right click in the Y axis and select Reference Lines
- The reference line for those that closed up will be a Band with a Scope of Cell, starting with the AVG(Open) and ending with the AGG(Closed Up). Colour it the same as the wick colour.
That leaves those that closed down which, as you might expect, is very similar to building the candle for Closed Up:
- Create a new calculated field called Closed Down
- The formula for Closed Down is IF AVG([Open])> AVG([Close]) THEN AVG([Open]) END
- Drag Closed Down to the Detail shelf
- Right click in the Y axis to add a new reference line and set it up as follows:
Now you should see a completed candlestick chart in Tableau.
In the candlestick dashboard I also added a Volume chart, which is very simple to do. It’s a simple bar chart coloured using the [Up or Down] pill.
Download the workbook from Tableau Public to see how it was all put together.
Other useful chart types you may want to build in Tableau include: