Charting is an essential tool for technical analysis. The charting functions described below allow you to create custom charts for price/volume, and indicator data.
| Function | Description |
|---|---|
| indchart | Indicator Chart |
| chartoptions | Create chartoptions object |
| stockchart | Create stock chart form historical data |
| addindicator | Add indicators to stock charts |
| addoverlay | Add overlays to stock charts |
To easily and quickly visualized indicators, use indchart with arguments detailed in the table below.
Syntax |
|||
|---|---|---|---|
indchart(stockasset object, indicatordata, chartperiod,
charttype, histoff)
|
|||
| Argument | Options | Description | Default |
stockasset object |
stockasset object |
Stockasset object from which the indicator was calculated.
This provides the 'Dates' if labeling the time-axis is desired. If no
input, then time-axis is labeled as data point number. |
optional |
| DateCellString |
cell array of date strings |
A cell array of date strings in the format 'yyyymmdd'. This is the equivalent format the the 'Dates' filed of the stockasset object. Provides time-axis labeling if desired. If no input, then time-axis is labeled as data point number. | optional |
indicatordata |
[n x m] double array |
Column array of indicator data. If there is more than one column,
then the second column is plotted as a 'trigger' line. If the chart
type is 'centered', than a 'histogram' is added unless 'histoff' is
added as an input argument.
|
REQUIRED |
chartperiod |
'#days'
'#months'
'#years'
|
Number of days months, or years.
Examples: '30days', '2months',
'1year'.
|
'3months' |
charttype |
'banded' 'centered' |
'banded': Draw indicator
bound between 0 and 100 (-100 for Williams %R) with oversold and overbought
levels defined in the following argument.
Example: ...'banded', [20 80],... 'centered': Draw unbounded
indicator |
'centered' |
histoff |
'histoff' |
To not include a 'histogram' plot, include 'histoff' as an argument | include histogram |
See examples: Indicator Charts
The most convienent way to set your preferences for charting is via the 'chartoptions' class object. This is a structue which contains all of the relevant information regarding chart type, chart period, volume on/off, and colorstyle. Input properties and their options are detailed below. All properties are optional, and defaults will be used if the are not explicitly defined.
Syntax |
|||
|---|---|---|---|
coptions = chartoptions(charttype, chartperiod, colorscheme, showvolume); |
|||
| Property | Options | Description | Default |
charttype |
'candle'
'ohlc'
'line'
'pct' |
Candlestick
Open High Low Close
Close only
Percent change of close line |
'candle' |
chartperiod |
'#days'
'#months'
'#years'
|
Number of days months, or years.
Examples: '30days', '2months',
'1year'.
|
'3months' |
colorscheme |
'cs1', 'cs2',
'cs3' |
'cs1': red for down day, green for
up day
'cs2': red for down day, black for
up day
'cs3': black for down day, white for
up day
|
'cs1' |
showvolume |
'voff' |
If 'voff', then do not
add volume. Otherwise it will be added by default.
|
Show volume |
See examples: Chart Types, Color Schemes
The stockchart function creates a price and volume chart from historical stock data. Required inputs are a stockasset object, and a chartoptions object. Optional inputs are 'subplot' followed by the 3 element vector defining the number of rows (nrows), number of columns (ncols) and n-th chart in the subplot to draw. This follows the Matlab syntax for 'subplot'.
Creating figures with multiple charts is easily done via the optional 'subplot' argument with stockchart. To create a figure with [n x m] charts, include the argument 'subplot' followed by the 3 element vector defining the number of rows (nrows), number of columns (ncols) and n-th chart in the subplot to draw. This syntax is consistnet with the Matlab syntax for 'subplot'.
Syntax |
||
|---|---|---|
hgroup = stockchart(stockasset object, chartoptions object, {'subplot', [nrows ncols n]}); |
||
| Argument | Description | Default |
stockasset object |
stockasset object created |
REQUIRED |
chartoptions object |
chartoptions object created with 'chartoptions'
|
REQUIRED |
| 'subplot' |
'subplot' followed by [nrows ncols n], where n is the index of the chart in the array to draw. This follows the Matlab® syntax for 'subplot' | [1 1 1] |
See examples: Chart Types, Color Schemes, Multiple Charting
The 'addindicator' function adds a chart of column vector indicatordata to an existing stockchart referenced by hgroup. It returns a handle group of the input handle group with itself appended. If indicatordata is an [n x m] column vector of indicator data, and m = 2, then the m=2 column will be plotted as a 'trigger' line. If the chart type is 'centered', than a 'histogram' is added.
Defining the type of indicator data as 'centered', or 'banded', will determine the style of indicator chart to add.
Syntax |
|||
|---|---|---|---|
hgroup = addindicator(hgroup,indicatordata,charttype, userlabel); |
|||
| Argument | Options | Description | Default |
hgroup |
[h1,h2,h3...] |
Must be a vector of handles to an existing stockchart
group. |
REQUIRED |
indicatordata |
[n x m] double array
|
Indicator data to add to chart. If m>1, then the m=2 column
is plotted as a 'trigger' line. If the chart type is 'centered', than
a 'histogram' is added.
|
REQUIRED |
charttype |
'banded' 'centered' |
'banded': Draw indicator
bound between 0 and 100 (-100 for Williams %R) with oversold and overbought
levels defined in the following argument.
Example: ...'banded', [20 80],... 'centered': Draw unbounded
indicator |
'centered' |
| userlabel |
string |
Any string is acceptable except for reserved strings: 'banded', 'centered' | '' |
See example: Adding Indicators
The addoverlay function adds overlaydata to the existing stockchart referenced by hgroup. The output is a handle to the overlay graphics object.
Syntax |
|||
|---|---|---|---|
ha = addoverlay(hgroup,overlaydata, userlabel); |
|||
| Argument | Options | Description | Default |
hgroup |
[h1,h2,h3...] |
Must be a vector of handles to an existing stockchart
group. |
REQUIRED |
overlaydata |
[n x m] double array
|
Overlay data to add to chart.
|
REQUIRED |
| userlabel |
string |
Any string is acceptable. | '' |
See example: Adding Overlays



Continue from 'Adding Indicators' above:

