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: query(date)
      open: query(open)
      high: query(high)
      low: query(low)
      close: query(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: query(date)
      open: query(open)
      high: query(high)
      low: query(low)
      close: query(close)
  - name: Volume Trace
    model: ref(stock-data-with-volume)
    props:
      type: bar
      x: query(date)
      y: query(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: query(date)
      open: query(open)
      high: query(high)
      low: query(low)
      close: query(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)"

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: 'data array' #(1)!
customdata: 'data array' #(2)!
decreasing:
  fillcolor: 'color' #(3)!
  line:
    color: 'color' #(4)!
    width: 'number greater than or equal to 0' #(5)!
high: 'data array' #(6)!
hoverinfo: 'flaglist string. any combination of "x", "y", "z", "text", "name" joined
  with a "+" or "all" or "none" or "skip".' #(7)!
hoverlabel:
  align: 'enumerated or array of enumerateds , one of ( "left" | "right" | "auto"
    )' #(8)!
  bgcolor: 'color or array of colors' #(9)!
  bordercolor: 'color or array of colors' #(10)!
  font:
    color: color or array of colors
    family: 'string or array of strings' #(11)!
    size: number or array of numbers greater than or equal to 1
  namelength: 'integer or array of integers greater than or equal to -1' #(12)!
  split: 'boolean' #(13)!
hovertext: 'string or array of strings' #(14)!
ids: 'data array' #(15)!
increasing:
  fillcolor: 'color' #(16)!
  line:
    color: 'color' #(17)!
    width: 'number greater than or equal to 0' #(18)!
legendgroup: 'string' #(19)!
legendgrouptitle:
  font:
    color: color
    family: 'string' #(20)!
    size: number greater than or equal to 1
  text: 'string' #(21)!
legendrank: 'number' #(22)!
legendwidth: 'number greater than or equal to 0' #(23)!
line:
  width: 'number greater than or equal to 0' #(24)!
low: 'data array' #(25)!
meta: 'number or categorical coordinate string' #(26)!
opacity: 'number between or equal to 0 and 1' #(27)!
open: 'data array' #(28)!
selectedpoints: 'number or categorical coordinate string' #(29)!
showlegend: 'boolean' #(30)!
text: 'string or array of strings' #(31)!
type: candlestick
uirevision: 'number or categorical coordinate string' #(32)!
visible: 'enumerated , one of ( true | false | "legendonly" )' #(33)!
whiskerwidth: 'number between or equal to 0 and 1' #(34)!
x: 'data array' #(35)!
xaxis: 'subplotid' #(36)!
xcalendar: 'enumerated , one of ( "chinese" | "coptic" | "discworld" | "ethiopian"
  | "gregorian" | "hebrew" | "islamic" | "jalali" | "julian" | "mayan" | "nanakshahi"
  | "nepali" | "persian" | "taiwan" | "thai" | "ummalqura" )' #(37)!
xhoverformat: 'string' #(38)!
xperiod: 'number or categorical coordinate string' #(40)!
xperiod0: 'number or categorical coordinate string' #(39)!
xperiodalignment: 'enumerated , one of ( "start" | "middle" | "end" )' #(41)!
yaxis: 'subplotid' #(42)!
yhoverformat: 'string' #(43)!
  1. Sets the close values.
  2. 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
  3. Sets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available.
  4. Sets the color of line bounding the box(es).
  5. Sets the width (in px) of line bounding the box(es).
  6. Sets the high values.
  7. 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.
  8. 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
  9. Sets the background color of the hover labels for this trace
  10. Sets the border color of the hover labels for this trace.
  11. HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts if they aren't available on the system. The Chart Studio Cloud (at https://chart-studio.plotly.com or on-premise) generates images on a server, where only a select number of fonts are installed and supported. These include "Arial", "Balto", "Courier New", "Droid Sans",, "Droid Serif", "Droid Sans Mono", "Gravitas One", "Old Standard TT", "Open Sans", "Overpass", "PT Sans Narrow", "Raleway", "Times New Roman".
  12. 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.
  13. Show hover information (open, close, high, low) in separate labels.
  14. Same as text.
  15. 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.
  16. Sets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available.
  17. Sets the color of line bounding the box(es).
  18. Sets the width (in px) of line bounding the box(es).
  19. Sets the legend group for this trace. Traces part of the same legend group hide/show at the same time when toggling legend items.
  20. HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts if they aren't available on the system. The Chart Studio Cloud (at https://chart-studio.plotly.com or on-premise) generates images on a server, where only a select number of fonts are installed and supported. These include "Arial", "Balto", "Courier New", "Droid Sans",, "Droid Serif", "Droid Sans Mono", "Gravitas One", "Old Standard TT", "Open Sans", "Overpass", "PT Sans Narrow", "Raleway", "Times New Roman".
  21. Sets the title of the legend group.
  22. 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.
  23. Sets the width (in px or fraction) of the legend for this trace.
  24. 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.
  25. Sets the low values.
  26. Assigns extra meta information associated with this trace that can be used in various text attributes. Attributes such as trace name, graph, axis and colorbar title.text, annotation text rangeselector, updatemenues and sliders label text all support meta. To access the trace meta values in an attribute in the same trace, simply use %{meta[i]} where i is the index or key of the meta item in question. To access trace meta in layout attributes, use %{data[n[.meta[i]} where i is the index or key of the meta and n is the trace index.
  27. Sets the opacity of the trace.
  28. Sets the open values.
  29. Array containing integer indices of selected points. Has an effect only for traces that support selections. Note that an empty array means an empty selection where the unselected are turned on for all points, whereas, any other non-array values means no selection all where the selected and unselected styles have no effect.
  30. Determines whether or not an item corresponding to this trace is shown in the legend.
  31. 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.
  32. Controls persistence of some user-driven changes to the trace: constraintrange in parcoords traces, as well as some editable: true modifications such as name and colorbar.title. Defaults to layout.uirevision. Note that other user-driven trace attribute changes are controlled by layout attributes: trace.visible is controlled by layout.legend.uirevision, selectedpoints is controlled by layout.selectionrevision, and colorbar.(x|y) (accessible with config: {editable: true}) is controlled by layout.editrevision. Trace changes are tracked by uid, which only falls back on trace index if no uid is provided. So if your app can add/remove traces before the end of the data array, such that the same trace has a different index, you can still preserve user-driven changes if you give each trace a uid that stays with it as it moves.
  33. 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).
  34. Sets the width of the whiskers relative to the box' width. For example, with 1, the whiskers are as wide as the box(es).
  35. Sets the x coordinates. If absent, linear coordinate will be generated.
  36. 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.
  37. Sets the calendar system to use with x date data.
  38. 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.46"By default the values are formatted using xaxis.hoverformat.
  39. Only relevant when the axis type is "date". Sets the base for period positioning in milliseconds or date string on the x0 axis. When x0period is round number of weeks, the x0period0 by default would be on a Sunday i.e. 2000-01-02, otherwise it would be at 2000-01-01.
  40. Only relevant when the axis type is "date". Sets the period positioning in milliseconds or "M" on the x axis. Special values in the form of "M" could be used to declare the number of months. In this case n must be a positive integer.
  41. Only relevant when the axis type is "date". Sets the alignment of data points on the x axis.
  42. 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.
  43. 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.46"By default the values are formatted using yaxis.hoverformat.