Skip to content

Candlestick

Overview

The candlestick trace type is commonly used in financial analysis to visualize the price movements of a stock or asset over time. It requires open, high, low, and close (OHLC) data and is useful for tracking the performance of a stock or identifying market trends.

You can control the appearance of candlestick charts through attributes such as increasing, decreasing, line, fillcolor, and more to highlight upward and downward trends in the market.

Common Uses

  • Stock Market Analysis: Visualizing the performance of stocks over time.
  • Trend Identification: Identifying market trends such as uptrends, downtrends, or reversals.
  • Price Fluctuation Visualization: Showing how stock prices move within a specific time period (daily, weekly, etc.).

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple candlestick plot showing stock price movements over a period:

You can copy this code below to create this chart in your project:

models:
  - name: stock-data
    args:
      - echo
      - |
        date,open,high,low,close
        2024-01-01,100,105,95,102
        2024-01-02,102,108,99,104
        2024-01-03,104,110,100,108
        2024-01-04,108,112,101,107
        2024-01-05,107,109,98,103
traces:
  - name: Simple Candlestick Plot
    model: ${ref(stock-data)}
    props:
      type: candlestick
      x: ?{date}
      open: ?{open}
      high: ?{high}
      low: ?{low}
      close: ?{close}
charts:
  - name: Simple Candlestick Chart
    traces:
      - ${ref(Simple Candlestick Plot)}
    layout:
      title:
        text: Simple Candlestick Chart<br><sub>Stock Price Movements</sub>
      xaxis:
        rangeslider:
          visible: false
        title:
          text: "Date"
      yaxis:
        title:
          text: "Price (USD)"

This example includes both candlestick data and volume, providing additional insights into the market activity:

Here's the code:

models:
  - name: stock-data-with-volume
    args:
      - echo
      - |
        date,open,high,low,close,volume
        2024-01-01,100,105,95,102,1000000
        2024-01-02,102,108,99,104,1200000
        2024-01-03,104,110,100,108,1500000
        2024-01-04,108,112,101,107,1100000
        2024-01-05,107,109,98,103,1300000
traces:
  - name: Candlestick Plot with Volume
    model: ${ref(stock-data-with-volume)}
    props:
      type: candlestick
      x: ?{date}
      open: ?{open}
      high: ?{high}
      low: ?{low}
      close: ?{close}
  - name: Volume Trace
    model: ${ref(stock-data-with-volume)}
    props:
      type: bar
      x: ?{date}
      y: ?{volume}
      yaxis: "y2"
      marker:
        opacity: .5
        color: 'blue'
charts:
  - name: Candlestick Chart with Volume
    traces:
      - ${ref(Candlestick Plot with Volume)}
      - ${ref(Volume Trace)}
    layout:
      showlegend: false

      title:
        text: Candlestick Chart with Volume<br><sub>Stock Price and Volume</sub>
      xaxis:
        title:
          text: "Date"
        rangeslider: 
          visible: false
      yaxis:
        title:
          text: "Price (USD)"

      yaxis2:
        title:
          text: "Volume"
        overlaying: "y"
        side: "right"
        range: [0, 10000000]

Here's a candlestick chart with customized colors for increasing and decreasing stock prices:

You can copy this code below to create this chart in your project:

models:
  - name: stock-data-colored
    args:
      - echo
      - |
        date,open,high,low,close
        2024-01-01,100,105,95,102
        2024-01-02,102,108,99,104
        2024-01-03,104,110,100,108
        2024-01-04,108,112,101,107
        2024-01-05,107,109,98,103
traces:
  - name: Colored Candlestick Plot
    model: ${ref(stock-data-colored)}
    props:
      type: candlestick
      x: ?{date}
      open: ?{open}
      high: ?{high}
      low: ?{low}
      close: ?{close}
      increasing:
        line:
          color: "#17becf"
      decreasing:
        line:
          color: "#d62728"
charts:
  - name: Candlestick with Custom Colors
    traces:
      - ${ref(Colored Candlestick Plot)}
    layout:
      title:
        text: Colored Candlestick Chart<br><sub>Stock Price Movements with Custom Colors</sub>
      xaxis:
        title:
          text: "Date"
      yaxis:
        title:
          text: "Price (USD)"

A schema to validate plotly trace properties

Attributes

These attributes apply to traces where trace.props.type is set to candlestick. You would configure these attributes on the trace with the trace.props object.

close: 'array' #(1)!
closesrc: 'string' #(2)!
customdata: 'array' #(3)!
customdatasrc: 'string' #(4)!
decreasing:
  fillcolor: 'any' #(5)!
  line:
    color: 'any' #(6)!
    width: 'number' #(7)!
high: 'array' #(8)!
highsrc: 'string' #(9)!
hoverinfo: 'array' #(10)!
hoverinfosrc: 'string' #(11)!
hoverlabel:
  align: 'array' #(12)!
  alignsrc: 'string' #(13)!
  bgcolor: 'color | array' #(14)!
  bgcolorsrc: 'string' #(15)!
  bordercolor: 'color | array' #(16)!
  bordercolorsrc: 'string' #(17)!
  font:
    color: color | array
    colorsrc: 'string' #(18)!
    family: 'string | array' #(19)!
    familysrc: 'string' #(20)!
    lineposition: 'array' #(21)!
    linepositionsrc: 'string' #(22)!
    shadow: 'string | array' #(23)!
    shadowsrc: 'string' #(24)!
    size: number | array
    sizesrc: 'string' #(25)!
    style: 'array' #(26)!
    stylesrc: 'string' #(27)!
    textcase: 'array' #(28)!
    textcasesrc: 'string' #(29)!
    variant: 'array' #(30)!
    variantsrc: 'string' #(31)!
    weight: 'integer | array' #(32)!
    weightsrc: 'string' #(33)!
  namelength: 'integer | array' #(34)!
  namelengthsrc: 'string' #(35)!
  split: 'boolean' #(36)!
hovertext: 'string | array' #(37)!
hovertextsrc: 'string' #(38)!
ids: 'array' #(39)!
idssrc: 'string' #(40)!
increasing:
  fillcolor: 'any' #(41)!
  line:
    color: 'any' #(42)!
    width: 'number' #(43)!
legend: 'string' #(44)!
legendgroup: 'string' #(45)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(46)!
    lineposition: 'string' #(47)!
    shadow: 'string' #(48)!
    size: number
    style: 'any' #(49)!
    textcase: 'any' #(50)!
    variant: 'any' #(51)!
    weight: 'integer' #(52)!
  text: 'string' #(53)!
legendrank: 'number' #(54)!
legendwidth: 'number' #(55)!
line:
  width: 'number' #(56)!
low: 'array' #(57)!
lowsrc: 'string' #(58)!
metasrc: 'string' #(59)!
name: 'string' #(60)!
opacity: 'number' #(61)!
open: 'array' #(62)!
opensrc: 'string' #(63)!
showlegend: 'boolean' #(64)!
stream:
  maxpoints: 'number' #(65)!
  token: 'string' #(66)!
text: 'string | array' #(67)!
textsrc: 'string' #(68)!
type: candlestick
uid: 'string' #(69)!
visible: 'any' #(70)!
whiskerwidth: 'number' #(71)!
x: 'array' #(72)!
xaxis: 'string' #(73)!
xcalendar: 'any' #(74)!
xhoverformat: 'string' #(75)!
xperiodalignment: 'any' #(76)!
xsrc: 'string' #(77)!
yaxis: 'string' #(78)!
yhoverformat: 'string' #(79)!
zorder: 'integer' #(80)!
  1. Sets the close values.
  2. Sets the source reference on Chart Studio Cloud for close.
  3. Assigns extra data each datum. This may be useful when listening to hover, click and selection events. Note that, scatter traces also appends customdata items in the markers DOM elements
  4. Sets the source reference on Chart Studio Cloud for customdata.
  5. Sets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available.
  6. Sets the color of line bounding the box(es).
  7. Sets the width (in px) of line bounding the box(es).
  8. Sets the high values.
  9. Sets the source reference on Chart Studio Cloud for high.
  10. Determines which trace information appear on hover. If none or skip are set, no information is displayed upon hovering. But, if none is set, click and hover events are still fired.
  11. Sets the source reference on Chart Studio Cloud for hoverinfo.
  12. Sets the horizontal alignment of the text content within hover label box. Has an effect only if the hover label text spans more two or more lines
  13. Sets the source reference on Chart Studio Cloud for align.
  14. Sets the background color of the hover labels for this trace
  15. Sets the source reference on Chart Studio Cloud for bgcolor.
  16. Sets the border color of the hover labels for this trace.
  17. Sets the source reference on Chart Studio Cloud for bordercolor.
  18. Sets the source reference on Chart Studio Cloud for color.
  19. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  20. Sets the source reference on Chart Studio Cloud for family.
  21. Sets the kind of decoration line(s) with text, such as an under, over or through as well as combinations e.g. under+over, etc.
  22. Sets the source reference on Chart Studio Cloud for lineposition.
  23. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  24. Sets the source reference on Chart Studio Cloud for shadow.
  25. Sets the source reference on Chart Studio Cloud for size.
  26. Sets whether a font should be styled with a normal or italic face from its family.
  27. Sets the source reference on Chart Studio Cloud for style.
  28. Sets capitalization of text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.
  29. Sets the source reference on Chart Studio Cloud for textcase.
  30. Sets the variant of the font.
  31. Sets the source reference on Chart Studio Cloud for variant.
  32. Sets the weight (or boldness) of the font.
  33. Sets the source reference on Chart Studio Cloud for weight.
  34. Sets the default length (in number of characters) of the trace name in the hover labels for all traces. -1 shows the whole name regardless of length. 0-3 shows the first 0-3 characters, and an integer >3 will show the whole name if it is less than that many characters, but if it is longer, will truncate to namelength - 3 characters and add an ellipsis.
  35. Sets the source reference on Chart Studio Cloud for namelength.
  36. Show hover information (open, close, high, low) in separate labels.
  37. Same as text.
  38. Sets the source reference on Chart Studio Cloud for hovertext.
  39. Assigns id labels to each datum. These ids for object constancy of data points during animation. Should be an array of strings, not numbers or any other type.
  40. Sets the source reference on Chart Studio Cloud for ids.
  41. Sets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available.
  42. Sets the color of line bounding the box(es).
  43. Sets the width (in px) of line bounding the box(es).
  44. Sets the reference to a legend to show this trace in. References to these legends are legend, legend2, legend3, etc. Settings for these legends are set in the layout, under layout.legend, layout.legend2, etc.
  45. Sets the legend group for this trace. Traces and shapes part of the same legend group hide/show at the same time when toggling legend items.
  46. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  47. Sets the kind of decoration line(s) with text, such as an under, over or through as well as combinations e.g. under+over, etc.
  48. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  49. Sets whether a font should be styled with a normal or italic face from its family.
  50. Sets capitalization of text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.
  51. Sets the variant of the font.
  52. Sets the weight (or boldness) of the font.
  53. Sets the title of the legend group.
  54. Sets the legend rank for this trace. Items and groups with smaller ranks are presented on top/left side while with reversed legend.traceorder they are on bottom/right side. The default legendrank is 1000, so that you can use ranks less than 1000 to place certain items before all unranked items, and ranks greater than 1000 to go after all unranked items. When having unranked or equal rank items shapes would be displayed after traces i.e. according to their order in data and layout.
  55. Sets the width (in px or fraction) of the legend for this trace.
  56. Sets the width (in px) of line bounding the box(es). Note that this style setting can also be set per direction via increasing.line.width and decreasing.line.width.
  57. Sets the low values.
  58. Sets the source reference on Chart Studio Cloud for low.
  59. Sets the source reference on Chart Studio Cloud for meta.
  60. Sets the trace name. The trace name appears as the legend item and on hover.
  61. Sets the opacity of the trace.
  62. Sets the open values.
  63. Sets the source reference on Chart Studio Cloud for open.
  64. Determines whether or not an item corresponding to this trace is shown in the legend.
  65. Sets the maximum number of points to keep on the plots from an incoming stream. If maxpoints is set to 50, only the newest 50 points will be displayed on the plot.
  66. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  67. Sets hover text elements associated with each sample point. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to this trace's sample points.
  68. Sets the source reference on Chart Studio Cloud for text.
  69. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  70. Determines whether or not this trace is visible. If legendonly, the trace is not drawn, but can appear as a legend item (provided that the legend itself is visible).
  71. Sets the width of the whiskers relative to the box' width. For example, with 1, the whiskers are as wide as the box(es).
  72. Sets the x coordinates. If absent, linear coordinate will be generated.
  73. Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If x (the default value), the x coordinates refer to layout.xaxis. If x2, the x coordinates refer to layout.xaxis2, and so on.
  74. Sets the calendar system to use with x date data.
  75. Sets the hover text formatting rulefor x using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted using xaxis.hoverformat.
  76. Only relevant when the axis type is date. Sets the alignment of data points on the x axis.
  77. Sets the source reference on Chart Studio Cloud for x.
  78. Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If y (the default value), the y coordinates refer to layout.yaxis. If y2, the y coordinates refer to layout.yaxis2, and so on.
  79. Sets the hover text formatting rulefor y using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted using yaxis.hoverformat.
  80. Sets the layer on which this trace is displayed, relative to other SVG traces on the same subplot. SVG traces with higher zorder appear in front of those with lower zorder.