OHLC Plot
OHLC (Open-High-Low-Close) plots are a common data visualization tool used in finance to represent the price data of a financial instrument over a specific time frame. Similar to Candlesticks, they display four key prices: the opening price (open), the highest price (high), the lowest price (low), and the closing price (close), typically as vertical bars on a chart, providing insights into price movements and trends.
In OHLC plots, each bar consists of a vertical line with small horizontal lines on both ends. The top of the vertical line represents the high price, the bottom represents the low price, the horizontal line on the left indicates the opening price, and the horizontal line on the right signifies the closing price. Additionally, the color of the bar is often used to indicate whether the closing price was higher (bullish, often green) or lower (bearish, often red) than the opening price, aiding in the quick assessment of price trends and market sentiment. Analyzing the shape, color, and position of these bars helps traders and analysts assess the price movement, trends, and market sentiment within a given time frame.
What are OHLC plots useful for?
- Price trend analysis: OHLC charts provide a clear visual representation of price trends and movements over specific time periods, helping traders and analysts assess market direction.
- Identifying support and resistance: They aid in identifying support and resistance levels, key price points that can inform trading decisions and risk management.
- Quantitative analysis: OHLC data can be leveraged for quantitative analysis, statistical modeling, and the development of trading strategies, making them valuable in algorithmic and systematic trading.
Examples
A basic OHLC plot
Visualize the key summary statistics of a stock price as it evolves. Pass the column name of the instrument to x
, and pass the open
, high
, low
, and close
arguments the appropriate column names.
import deephaven.plot.express as dx
import deephaven.agg as agg
stocks = dx.data.stocks()
# compute ohlc per symbol for each minute
stocks_1min_ohlc = stocks.update_view(
"BinnedTimestamp = lowerBin(Timestamp, 'PT1m')"
).agg_by(
[
agg.first("Open=Price"),
agg.max_("High=Price"),
agg.min_("Low=Price"),
agg.last("Close=Price"),
],
by=["Sym", "BinnedTimestamp"],
)
# create a basic candlestick plot - the `open`, `high`, `low`, and `close` arguments must be specified
ohlc_plot = dx.ohlc(
stocks_1min_ohlc.where("Sym == `DOG`"),
x="BinnedTimestamp",
open="Open",
high="High",
low="Low",
close="Close",
)
API Reference
Returns an ohlc chart
Returns: DeephavenFigure
A DeephavenFigure that contains the ohlc chart
Parameters | Type | Default | Description |
---|---|---|---|
table | Table | DataFrame | A table to pull data from. | |
x | str | None | None | The column containing x-axis data |
open | str | list[str] | None | None | The column containing the open data |
high | str | list[str] | None | None | The column containing the high data |
low | str | list[str] | None | None | The column containing the low data |
close | str | list[str] | None | None | The column containing the close data |
increasing_color_sequence | list[str] | None | None | A list of colors to sequentially apply to the series on increasing bars. The colors loop, so if there are more series than colors, colors will be reused. |
decreasing_color_sequence | list[str] | None | None | A list of colors to sequentially apply to the series on decreasing bars. The colors loop, so if there are more series than colors, colors will be reused. |
xaxis_sequence | list[int] | None | None | A list of x axes to assign series to. Odd numbers starting with 1 are created on the bottom x axis and even numbers starting with 2 are created on the top x axis. Axes are created up to the maximum number specified. The axes loop, so if there are more series than axes, axes will be reused. |
yaxis_sequence | list[int] | None | None | A list of y axes to assign series to. Odd numbers starting with 1 are created on the left y axis and even numbers starting with 2 are created on the top y axis. Axes are created up to the maximum number specified. The axes loop, so if there are more series than axes, axes will be reused. |
yaxis_titles | list[str] | None | None | A list of titles to sequentially apply to the y axes. The titles do not loop. |
xaxis_titles | list[str] | None | None | A list of titles to sequentially apply to the x axes. The titles do not loop. |
unsafe_update_figure | Callable | <function default_callback> | An update function that takes a plotly figure as an argument and optionally returns a plotly figure. If a figure is not returned, the plotly figure passed will be assumed to be the return value. Used to add any custom changes to the underlying plotly figure. Note that the existing data traces should not be removed. This may lead to unexpected behavior if traces are modified in a way that break data mappings. |