Candlestick Plot

Candlestick plots are a financial data visualization tool commonly used in technical analysis. Similar to an OHLC, they also represent the open, close, high, and low prices of a financial instrument for a specific time period, providing insights into price movements and patterns, and aiding in the identification of trends and potential reversal points in financial markets.

Interpreting a candlestick chart involves understanding the visual representation of price data within a specific time frame. Each candlestick consists of a rectangular “body” representing the price range between the opening and closing prices, with the “wick” or “shadow” lines extending above and below the body indicating the high and low prices during that time period.

In a bullish (upward, typically shown as green) candlestick, the open is typically at the bottom of the body, and the close is at the top, indicating a price increase. In a bearish (downward, typically shown as red) candlestick, the open is at the top of the body, and the close is at the bottom, suggesting a price decrease. One can use these patterns, along with the length of the wicks and the context of adjacent candlesticks, to analyze trends.

What are candlestick plots useful for?

  • Analyzing financial markets: Candlestick plots are a standard tool in technical analysis for understanding price movements, identifying trends, and potential reversal points in financial instruments, such as stocks, forex, and cryptocurrencies.
  • Short to medium-term trading: Candlestick patterns are well-suited for short to medium-term trading strategies, where timely decisions are based on price patterns and trends over a specific time frame.
  • Visualizing variation in price data: Candlestick plots offer a visually intuitive way to represent variability in price data, making them valuable for traders and analysts who prefer a visual approach to data analysis.

Examples

A basic candlestick plot

Visualize the key summary statistics of a stock price as it evolves. Specify the column name of the instrument with 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"],
)

candlestick_plot = dx.candlestick(
    stocks_1min_ohlc.where("Sym == `DOG`"),
    x="BinnedTimestamp",
    open="Open",
    high="High",
    low="Low",
    close="Close",
)

API Reference

Returns a candlestick chart

Returns: DeephavenFigure A DeephavenFigure that contains the candlestick chart

ParametersTypeDefaultDescription
tableTable |
DataFrame
A table to pull data from.
xstr |
None
NoneThe column containing x-axis data
openstr |
list[str] |
None
NoneThe column containing the open data
highstr |
list[str] |
None
NoneThe column containing the high data
lowstr |
list[str] |
None
NoneThe column containing the low data
closestr |
list[str] |
None
NoneThe column containing the close data
increasing_color_sequencelist[str] |
None
NoneA 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_sequencelist[str] |
None
NoneA 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_sequencelist[int] |
None
NoneA 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_sequencelist[int] |
None
NoneA 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_titleslist[str] |
None
NoneA list of titles to sequentially apply to the y axes. The titles do not loop.
xaxis_titleslist[str] |
None
NoneA list of titles to sequentially apply to the x axes. The titles do not loop.
unsafe_update_figureCallable<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.