SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 2 Vol 1

CANDLESTICK PLOT

Name:
    CANDLESTICK PLOT
Type:
    Graphics Command
Purpose:
    Generates a candlestick plot.
Description:
    Candlestick plots are used to display data where there is an opening value and a closing value for a given time unit. For example, it can be used to display daily stock prices over a period of time. However, it can be applied to any data where there are start and end values for each time unit.

    Specifically, it draws a box between the opening and closing values. In addition, it draws a line from the open/close values to the minimum and maximum values for the time unit.

    The appearance of the plot can be controlled by settings for the LINE and REGION and their associated attribute setting commands. Specifically,

      Trace 1 - this is the box between the open and close values for the case where the close is higher than the open
      Trace 2 - this is the box between the open and close values for the case where the close is lower than the open
      Trace 3 - this is the line from the minimum of the open and close values to the minimum value
      Trace 4 - this is the line from the maximum of the open and close values to the maximum value

    Note that the REGION FILL switch is automatically set to ON for the first 2 traces.

    Two common choices are:

    1. Draw the boxes in green for the case where the close value is greater than the open value and draw the boxes in red for the case where the close value is less than the open value.

    2. Draw the boxes in white (i.e., empty) for the case where the close value is greater than the open value and draw the boxes in black for the case where the close value is less than the open value.

    This is demonstrated in the Program example below.

Syntax 1:
    CANDLESTICK PLOT <yopen> <yclose> <ylow> yhigh>
                            <SUBSET/EXCEPT/FOR qualification>
    where <yopen> is the response variable containing the opening values;
                <yclose> is the response variable containing the closing values;
                <ylow> is the response variable containing the minimum values;
                <yhigh> is the response variable containing the maximum values;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    For this syntax, the x-axis value is set to the sequence number.

Syntax 2:
    CANDLESTICK PLOT <yopen> <yclose> <ylow> yhigh> <x>
                            <SUBSET/EXCEPT/FOR qualification>
    where <yopen> is the response variable containing the opening values;
                <yclose> is the response variable containing the closing values;
                <ylow> is the response variable containing the minimum values;
                <yhigh> is the response variable containing the maximum values;
                <x> is the horizontal axis variable;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.
Examples:
    CANDLESTICK PLOT YOPEN YCLOSE YLOW YHIGH
    CANDLESTICK PLOT YOPEN YCLOSE YLOW YHIGH X
Note:
    The width of the box can be controlled by entering the command

      SET CANDLESTICK PLOT BAR WIDTH <value>

    The default value is -1 which means Dataplot will use

      (X(2) - X(1))/2

    where X is the horizontal axis value.

Default:
    None
Synonyms:
    None
Related Commands: Reference:
    Gregory M., Morris (2006), "Candlestick Charting Explained: Timeless Techniques for Trading Stocks and Futures," McGraw-Hill, ISBN 9780071461542.
Applications:
    Financial Graphics
Implementation Date:
    2025/06
Program:
     
    . Step 1:   Read the data
    .
    skip 25
    column limits 13 80
    read candlestick.dat yclose yopen ylow yhigh
    skip 0
    let n = size yopen
    .
    column limits 1 12
    loop for k = 1 1 n
        let irow = 25 + k
        row limits irow irow
        read string candlestick.dat s^k
    end of loop
    column limits
    row limits
    .
    . Step 2:   Set some plot control
    .
    case asis
    title case asis
    label case asis
    tic mark label case asis
    .
    xlimits 1 27
    major x1tic mark number 9
    minor x1tic mark number 2
    x1tic mark label format alpha
    x1tic mark label content ^s1 ^s4 ^s7 ^s10 ^s13 ^s16 ^s19 ^s22 ^s25
    tic mark offset units data
    x1tic mark offset 0.8 3.8
    x1tic mark label size 1.5
    .
    region fill color blue red
    line blank blank solid solid
    line color blue red black black
    .
    . Step 3:   Generate the plot
    .
    title Candlestick Plot
    y1label Price
    x1label Date
    x2label Blue: Close > Open, Red: Close < Open
    .
    candlestick plot yopen yclose ylow yhigh
    
        
Date created: 07/16/2025
Last updated: 07/16/2025

Please email comments on this WWW page to [email protected].