Skip to content

Ohlc

Overview

The ohlc insight 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 insight showing the Open, High, Low, and Close prices of a stock over time:

sources:
  - name: ohlc-data-source
    type: duckdb
    database: target/seeds/ohlc_data.duckdb
    seeds:
      - table_name: model
        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

models:
  - name: ohlc-data
    source: ${ref(ohlc-data-source)}
    sql: select * from model
insights:
  - name: Simple OHLC Insight
    props:
      type: ohlc
      x: ?{${ref(ohlc-data).date}}
      open: ?{${ref(ohlc-data).open}}
      high: ?{${ref(ohlc-data).high}}
      low: ?{${ref(ohlc-data).low}}
      close: ?{${ref(ohlc-data).close}}
      increasing:
        line:
          color: "#17becf"
      decreasing:
        line:
          color: "#ff7f0e"

charts:
  - name: Simple OHLC Chart
    insights:
      - ${ref(Simple OHLC Insight)}
    layout:
      title:
        text: Simple OHLC Chart<br><sub>Stock Price Movements Over Time</sub>
      xaxis:
        title:
          text: "Date"
      yaxis:
        title:
          text: "Price"

sources:
  - name: ohlc-data-width-source
    type: duckdb
    database: target/seeds/ohlc_data_width.duckdb
    seeds:
      - table_name: model
        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

models:
  - name: ohlc-data-width
    source: ${ref(ohlc-data-width-source)}
    sql: select * from model
insights:
  - name: OHLC with Custom Width
    props:
      type: ohlc
      x: ?{${ref(ohlc-data-width).date}}
      open: ?{${ref(ohlc-data-width).open}}
      high: ?{${ref(ohlc-data-width).high}}
      low: ?{${ref(ohlc-data-width).low}}
      close: ?{${ref(ohlc-data-width).close}}
      increasing:
        line:
          color: "#2ca02c"
      decreasing:
        line:
          color: "#d62728"
      line:
        width: 3

charts:
  - name: OHLC Chart with Custom Width
    insights:
      - ${ref(OHLC 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"

sources:
  - name: ohlc-data-multi-source
    type: duckdb
    database: target/seeds/ohlc_data_multi.duckdb
    seeds:
      - table_name: model
        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

models:
  - name: ohlc-data-multi
    source: ${ref(ohlc-data-multi-source)}
    sql: select * from model
insights:
  - name: OHLC for AAPL
    props:
      type: ohlc
      x: ?{${ref(ohlc-data-multi).date}}
      open: ?{${ref(ohlc-data-multi).open}}
      high: ?{${ref(ohlc-data-multi).high}}
      low: ?{${ref(ohlc-data-multi).low}}
      close: ?{${ref(ohlc-data-multi).close}}
      increasing:
        line:
          color: "#1f77b4"
      decreasing:
        line:
          color: "#ff7f0e"
    interactions:
      - filter: ?{${ref(ohlc-data-multi).stock} = 'AAPL'}


  - name: OHLC for MSFT
    props:
      type: ohlc
      x: ?{${ref(ohlc-data-multi).date}}
      open: ?{${ref(ohlc-data-multi).open}}
      high: ?{${ref(ohlc-data-multi).high}}
      low: ?{${ref(ohlc-data-multi).low}}
      close: ?{${ref(ohlc-data-multi).close}}
      increasing:
        line:
          color: "#2ca02c"
      decreasing:
        line:
          color: "#d62728"
    interactions:
      - filter: ?{${ref(ohlc-data-multi).stock} = 'MSFT'}


charts:
  - name: OHLC Chart with Multiple Stocks
    insights:
      - ${ref(OHLC for AAPL)}
      - ${ref(OHLC 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"