Skip to content

Ohlc

Overview

The ohlc trace type is used to create OHLC (Open, High, Low, Close) charts, which are commonly used to visualize stock market data or financial data over time. OHLC charts represent price movements for a given period using vertical bars for high and low prices, and tick marks for open and close prices.

You can customize the colors, bar widths, and date ranges to represent financial data effectively.

Common Uses

  • Stock Market Visualization: Displaying price movement data for stocks, currencies, or commodities.
  • Financial Time Series: Visualizing price fluctuations over time.
  • Trading Analysis: Understanding market trends through candlestick-like visualizations.

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple ohlc plot showing the Open, High, Low, and Close prices of a stock over time:

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

models:
  - name: ohlc-data
    args:
      - echo
      - |
        date,open,high,low,close
        2023-01-01,100,105,95,102
        2023-01-02,102,108,101,107
        2023-01-03,107,110,105,109
        2023-01-04,109,112,107,111
        2023-01-05,111,114,110,113
traces:
  - name: Simple OHLC Plot
    model: ref(ohlc-data)
    props:
      type: ohlc
      x: query(date)
      open: query(open)
      high: query(high)
      low: query(low)
      close: query(close)
      increasing:
        line:
          color: "#17becf"
      decreasing:
        line:
          color: "#ff7f0e"
charts:
  - name: Simple OHLC Chart
    traces:
      - ref(Simple OHLC Plot)
    layout:
      title:
        text: Simple OHLC Chart<br><sub>Stock Price Movements Over Time</sub>
      xaxis:
        title:
          text: "Date"
      yaxis:
        title:
          text: "Price"

This example demonstrates an ohlc plot with custom bar widths to adjust the spacing between the OHLC bars:

Here's the code:

models:
  - name: ohlc-data-width
    args:
      - echo
      - |
        date,open,high,low,close
        2023-02-01,200,205,195,202
        2023-02-02,202,208,201,207
        2023-02-03,207,210,205,209
        2023-02-04,209,212,207,211
        2023-02-05,211,214,210,213
traces:
  - name: OHLC Plot with Custom Width
    model: ref(ohlc-data-width)
    props:
      type: ohlc
      x: query(date)
      open: query(open)
      high: query(high)
      low: query(low)
      close: query(close)
      increasing:
        line:
          color: "#2ca02c"
      decreasing:
        line:
          color: "#d62728"
      line:
        width: 3
charts:
  - name: OHLC Chart with Custom Width
    traces:
      - ref(OHLC Plot with Custom Width)
    layout:
      title:
        text: OHLC Plot with Custom Width<br><sub>Stock Prices with Custom Bar Width</sub>
      xaxis:
        title:
          text: "Date"
      yaxis:
        title:
          text: "Price"

This example shows an ohlc plot comparing multiple stocks' Open, High, Low, and Close prices over time:

Here's the code:

models:
  - name: ohlc-data-multi
    args:
      - echo
      - |
        stock,date,open,high,low,close
        AAPL,2023-03-01,150,155,145,152
        AAPL,2023-03-02,152,158,150,156
        AAPL,2023-03-03,156,160,154,159
        MSFT,2023-03-01,250,255,245,252
        MSFT,2023-03-02,252,258,250,256
        MSFT,2023-03-03,256,260,254,259
traces:
  - name: OHLC Plot for AAPL
    model: ref(ohlc-data-multi)
    props:
      type: ohlc
      x: query(date)
      open: query(open where stock = "AAPL")
      high: query(high where stock = "AAPL")
      low: query(low where stock = "AAPL")
      close: query(close where stock = "AAPL")
      increasing:
        line:
          color: "#1f77b4"
      decreasing:
        line:
          color: "#ff7f0e"
  - name: OHLC Plot for MSFT
    model: ref(ohlc-data-multi)
    props:
      type: ohlc
      x: query(date)
      open: query(open where stock = "MSFT")
      high: query(high where stock = "MSFT")
      low: query(low where stock = "MSFT")
      close: query(close where stock = "MSFT")
      increasing:
        line:
          color: "#2ca02c"
      decreasing:
        line:
          color: "#d62728"
charts:
  - name: OHLC Chart with Multiple Stocks
    traces:
      - ref(OHLC Plot for AAPL)
      - ref(OHLC Plot for MSFT)
    layout:
      title:
        text: OHLC Chart with Multiple Stocks<br><sub>Comparing AAPL and MSFT Stock Prices</sub>
      xaxis:
        title:
          text: "Date"
      yaxis:
        title:
          text: "Price"

Attributes

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

close: 'data array' 
customdata: 'data array' 
decreasing:
  line:
    color: 'color' 
    dash: 'string' 
    width: 'number greater than or equal to 0' 
high: 'data array' 
hoverinfo: 'flaglist string. any combination of "x", "y", "z", "text", "name" joined
  with a "+" or "all" or "none" or "skip".' 
hoverlabel:
  align: 'enumerated or array of enumerateds , one of ( "left" | "right" | "auto"
    )' 
  bgcolor: 'color or array of colors' 
  bordercolor: 'color or array of colors' 
  font:
    color: color or array of colors
    family: 'string or array of strings' 
    size: number or array of numbers greater than or equal to 1
  namelength: 'integer or array of integers greater than or equal to -1' 
  split: 'boolean' 
hovertext: 'string or array of strings' 
ids: 'data array' 
increasing:
  line:
    color: 'color' 
    dash: 'string' 
    width: 'number greater than or equal to 0' 
legendgroup: 'string' 
legendgrouptitle:
  font:
    color: color
    family: 'string' 
    size: number greater than or equal to 1
  text: 'string' 
legendrank: 'number' 
legendwidth: 'number greater than or equal to 0' 
line:
  dash: 'string' 
  width: 'number greater than or equal to 0' 
low: 'data array' 
meta: 'number or categorical coordinate string' 
opacity: 'number between or equal to 0 and 1' 
open: 'data array' 
selectedpoints: 'number or categorical coordinate string' 
showlegend: 'boolean' 
text: 'string or array of strings' 
tickwidth: 'number between or equal to 0 and 0.5' 
type: ohlc
uirevision: 'number or categorical coordinate string' 
visible: 'enumerated , one of ( true | false | "legendonly" )' 
x: 'data array' 
xaxis: 'subplotid' 
xcalendar: 'enumerated , one of ( "chinese" | "coptic" | "discworld" | "ethiopian"
  | "gregorian" | "hebrew" | "islamic" | "jalali" | "julian" | "mayan" | "nanakshahi"
  | "nepali" | "persian" | "taiwan" | "thai" | "ummalqura" )' 
xhoverformat: 'string' 
xperiod: 'number or categorical coordinate string' 
xperiod0: 'number or categorical coordinate string' 
xperiodalignment: 'enumerated , one of ( "start" | "middle" | "end" )' 
yaxis: 'subplotid' 
yhoverformat: 'string'