Open, High, Low and Close (OHLC) Plots
The Open, High, Low and Close (OHLC) plot typically shows four prices of a security or commodity per time slice: the open and close of the time slice, and the highest and lowest values reached during the time slice.
This plotting method requires a dataset that includes one column containing the values for the X axis (time), and one column for each of the corresponding four values (open, high, low, close).
Data Sourcing
Open, High, Low and Close Plots can be created using data from tables or arrays.
Creating a OHLC Plot using Data from a Table
When data is sourced from a table, the following syntax can be used:
ohlcPlot("SeriesName", source, "Time", "Open", "High", "Low", "Close")
ohlcPlot
is the method used to create an Open, High, Low and Close chart."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.source
is the table that holds the data you want to plot."Time"
is the name (as a string) of the column to be used for the X axis."Open"
is the name of the column (as a string) holding the opening price."High"
is the name of the column (as a string) holding the highest price."Low"
is the name of the column (as a string) holding the lowest price."Close"
is the name of the column (as a string) holding the closing price.
Example
from deephaven import Plot
tOHLC = db.t("LearnDeephaven","EODTrades")\
.where("Ticker=`AAPL`", "ImportDate=`2017-11-01`", "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")
plotOHLC = Plot.ohlcPlot("AAPL", tOHLC, "EODTimestamp", "Open", "High", "Low", "Close")\
.xBusinessTime()\
.lineStyle(Plot.lineStyle(2))\
.chartTitle("AAPL OHLC - June-July 2017")\
.show()
tOHLC = db.t("LearnDeephaven","EODTrades")
.where("Ticker=`AAPL`", "ImportDate=`2017-11-01`", "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")
plotOHLC = ohlcPlot("AAPL", tOHLC, "EODTimestamp", "Open", "High", "Low", "Close")
.xBusinessTime()
.lineStyle(lineStyle(2))
.chartTitle("AAPL OHLC - June-July 2017")
.show()
The first line of the query creates the t1
table using data from the LearnDeephaven
namespace and the EODTrades
table. Multiple where()
methods are then used to filter the data to include only
- the
ImportDate
partition - the Ticker
AAPL
- the date range of June 1, 2017 through July 31, 2017.
The next line contains the information needed for the plot:
plotOHLC
is the name of the variable that will hold the chart.ohlcPlot
is the method.AAPL
is the name of the series to be used in the chart.tOHLC
is the table from which our data is being pulled.EODTimestamp
is the name of the column to be used for the X axis.Open, High, Low
, andClose
, are the names of the columns containing the four respective data points to be plotted on the Y axis.xBusinessTime()
limits the date to business days only.lineStyle()
andchartTitle()
provide component formatting to the table.- Finally, the
show()
method presents the chart in theplotOHLC
variable.
When the query above is processed, the following OHLC chart is produced, which represents the opening, high, low and closing price of AAPL over June and July 2017:
Creating an OHLC Plot using Data from an Array
When data is sourced from an array, the following syntax can be used:
ohlcPlot("SeriesName",[Time], [Open], [High], [Low], [Close])
ohlcPlot
is the method used to create an Open, High, Low and Close chart."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.[Time]
is the array containing the data to be used for the X axis.[Open]
is the array containing the data to be used for the opening price.[High]
is the array containing the data to be used for the highest price.[Low]
is the array containing the data to be used for the lowest price.[Close]
is the array containing the data to be used for the closing price.
OHLC Plotting Options
OHLC Plots with Shared Axes
Just like XY series plots, the Open, High, Low and Close plot can also be used to present multiple series on the same chart, including the use of multiple X or Y axes. An example of this follows:
from deephaven import Plot
t2OHLC = db.t("LearnDeephaven","EODTrades")\
.where("Ticker in `AAPL`, `MSFT`", "ImportDate=`2017-11-01`", "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")
plotOHLC2 = Plot.ohlcPlot("AAPL", t2OHLC.where("Ticker = `AAPL`"), "EODTimestamp", "Open", "High", "Low", "Close")\
.lineStyle(Plot.lineStyle(2))\
.twinX()\
.ohlcPlot("MSFT", t2OHLC.where("Ticker = `MSFT`"), "EODTimestamp", "Open", "High", "Low", "Close")\
.xBusinessTime()\
.lineStyle(Plot.lineStyle(2))\
.chartTitle("AAPL vs MSFT OHLC - June-July 2017")\
.show()
t2OHLC = db.t("LearnDeephaven","EODTrades")
.where("Ticker in `AAPL`, `MSFT`", "ImportDate=`2017-11-01`", "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")
plotOHLC2 = ohlcPlot("AAPL", t2OHLC.where("Ticker = `AAPL`"),"EODTimestamp","Open","High","Low","Close")
.lineStyle(lineStyle(2))
.twinX()
.ohlcPlot("MSFT", t2OHLC.where("Ticker = `MSFT`"),"EODTimestamp","Open","High","Low","Close")
.xBusinessTime()
.lineStyle(lineStyle(2))
.chartTitle("AAPL vs MSFT OHLC - June-July 2017")
.show()
The first line of the query creates the t2OHLC
table using data from the LearnDeephaven
namespace and the EODTrades
table. Multiple where()
methods are then used to filter the data to include only
- the
ImportDate
partition . - the Tickers
AAPL
andMSFT.
- the date range of June 1, 2017 through July 31, 2017.
The next line contains the information needed for the plot:
plotOHLC2
is the name of the variable that will hold the chart.ohlcPlot
is the method used to plot the first series.AAPL
is the name of the first series to be used in the chart.t2OHLC
is the table from which the data is being pulled..where("Ticker=`AAPL`")
filters the table to only theAAPL
Ticker.EODTimestamp
is the name of the column to be used for the X axis.Open, High, Low
, andClose
, are the names of the columns containing the four respective data points to be plotted on the Y axis.- the
lineStyle()
method needs to be assigned to each series, so this reference only applies to the first series.
twinX()
is used to show different Y axes.ohlcPlot
is the method used to plot the second series.-
MSFT
is the name of the second series to be used in the chart. t2OHLC
is the table from which the data is being pulled..where("Ticker=`MSFT`")
filters the table to only theMSFT
Ticker.EODTimestamp
is the name of the column to be used for the X axis.Open, High, Low
, andClose
, are the names of the columns containing the four respective data points to be plotted on the Y axis.- the
lineStyle()
method applies only to the second series.
-
xBusinessTime()
limits the date to business days only.chartTitle()
provides the title for the chart.- Finally, the
show()
method presents the chart in theplotAAPLvMSFT
variable.
When the query above is processed, the plot below is produced. In this plot, the opening, high, low and closing price of AAPL
and MSFT
are plotted. The twinX()
method is used to show the value scale for AAPL
on the left Y axis and the value scale for MSFT
on the right Y axis.
For additional formatting options, please refer to:
Last Updated: 16 February 2021 18:07 -04:00 UTC Deephaven v.1.20200928 (See other versions)
Deephaven Documentation Copyright 2016-2020 Deephaven Data Labs, LLC All Rights Reserved