Open, High, Low, Close (OHLC)
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").show()
ohlcPlot
is the method used to create an OHLC 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.show
tells Deephaven to draw the plot in the console.
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()
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()
This query plots the OHLC chart as follows:
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"
, and"Close"
, 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.2
refers to line width.
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]).show()
ohlcPlot
is the method used to create an OHLC 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.show
tells Deephaven to draw the plot in the console.
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:
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()
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()
This query plots the OHLC chart as follows:
plotOHLC2
is the name of the variable that will hold the chart.ohlcPlot
plots 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 the AAPL Ticker.EODTimestamp
is the name of the column to be used for the X axis."Open"
,"High"
, "Low"
, and"Close"
, 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
plots 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 the MSFT Ticker.EODTimestamp
is the name of the column to be used for the X axis."Open"
,"High"
,"Low"
, and"Close"
, are the names of the columns containing the four respective data points to be plotted on the Y axis.lineStyle()
applies only to the second series.
xBusinessTime()
limits the date to business days only.chartTitle()
provides the title for the chart.
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.