Gnuplot can create candlestick charts out of the box. These charts are often used for graphing financial data, with the middle block representing the difference between the open and close, and the high and low represented with lines protruding from the top and bottom of this box. The bars are colored differently depending on if the security’s price increased or decreased over this period of time. In gnuplot, losses are represented with filled bars.
Creating the graph is relatively easy. First you need a data file. This can be in a number of formats, but the following format is fairly common:
Once you have your data file, creating the graph is as simple as:
plot '<data_file>' using 1:2:4:3:5 with candlesticks
1:2:4:3:5 is the field order for date, open, low, high and close prices in the file. If your file has data in a different order, you will need to rearrange these numbers.
The following is a complete working example. We have two files;
bhp.dat which contains the price data for BHP on the Australian Stock Exchange, and
candlestick.gnuplot which contains the gnuplot instructions.
# BHP (Australian Stock Exchange)
set terminal pngcairo font "arial,10" size 500,500
set output 'candlestick.png'
set xdata time
set xrange ["2013-02-14":"2013-02-27"]
set yrange [*:*]
set datafile separator ","
plot 'bhp.dat' using 1:2:4:3:5 notitle with candlesticks
With these files, we can generate the graph on the command line with:
$ gnuplot candlestick.gnuplot
Which will generate
candlestick.png which will look like this: