Charting - Technical Analysis Toolbox™
Charting

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.

Contents

Functions

Examples

back to top

Functions

Function List

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

back to top


indchart

Description

To easily and quickly visualized indicators, use indchart with arguments detailed in the table below.

Input arguments table for 'indchart' function

Syntax

indchart(stockasset object, indicatordata, chartperiod, charttype, histoff)
indchart(DateCellString, indicatordata,...
indchart(indicatordata,...

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

back to top


chartoptions

Description

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.

Property table for 'chartoptions' class

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

back to top


stockchart

Description

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'.

Input arguments table for 'stockchart' function

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

back to top


addindicator

Description

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.

Input arguments table for 'addindicator' function

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

back to top


addoverlay

Description

The addoverlay function adds overlaydata to the existing stockchart referenced by hgroup. The output is a handle to the overlay graphics object.

Input arguments table for 'addoverlay' function

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

back to top

Examples

Chart Types

coptions1 = chartoptions('candle','3months');
coptions2 = chartoptions('ohlc', '3months');
coptions3 = chartoptions('line', '3months', 'voff');
coptions4 = chartoptions('pct', '3months', 'voff');

figure(1)
clf

hgroup = stockchart(MyStocks(iStock),coptions1,'subplot',[2 2 1]);
xlabel(hgroup(end),'Date')
title('coptions1: Candlestick','fontweight','bold')

hgroup = stockchart(MyStocks(iStock),coptions2,'subplot',[2 2 2]);
xlabel(hgroup(end),'Date')
title('coptions2: OHLC','fontweight','bold')

hgroup = stockchart(MyStocks(iStock),coptions3,'subplot',[2 2 3]);
xlabel(hgroup(end),'Date')
title('coptions3: Line, No Volume','fontweight','bold')

hgroup = stockchart(MyStocks(iStock),coptions4,'subplot',[2 2 4]);
xlabel(hgroup(end),'Date')
title('coptions4: Percent Change, No Volume','fontweight','bold')

image

 

back to top


Color Schemes

coptions1 = chartoptions('cs1', '3months');
coptions2 = chartoptions('cs2', '3months');
coptions3 = chartoptions('cs3', '3months'');

figure(1)
clf

hgroup = stockchart(MyStocks(iStock),coptions1,'subplot',[2 2 1]);
xlabel(hgroup(end),'Date')
title('cs1: Red/Green','fontweight','bold')

hgroup = stockchart(MyStocks(iStock),coptions2,'subplot',[2 2 2]);
xlabel(hgroup(end),'Date')
title('cs2: Red/Black','fontweight','bold')

hgroup = stockchart(MyStocks(iStock),coptions3,'subplot',[2 2 3]);
xlabel(hgroup(end),'Date')
title('cs3: Black/White, No Volume','fontweight','bold')

image

back to top


Adding Indicators

coptions = chartoptions('candle', '3months');
coptions.indicatorheight = 0.2;

accdist = MyStocks.accumdist;
mcd = MyStocks.macdiv;
stoch = MyStocks.fullstochosc;

figure(1)
clf
hgroup = stockchart(MyStocks(iStock),coptions);
hgroup = addindicator(hgroup,mcd{iStock}, 'centered', 'macd');
hgroup = addindicator(hgroup,accdist{iStock},'centered', 'A/D');
hgroup = addindicator(hgroup,stoch{iStock}(:,[3 4]), 'banded', [20 80], 'slowstoch');
xlabel(hgroup(end),'Date')
title(hgroup(1), 'Adding Indicators', 'fontweight', 'bold')

image

back to top


Adding Overlays

Continue from 'Adding Indicators' above:

...
bbands = MyStocks.bollingerbands;
addoverlay(hgroup,bbands{iStock}, 'BBands(20,2)')

image

back to top


Multiple Charting

coptions = chartoptions('candle','3months');
nrows = 2;
ncols = 4;
accdist = MyStocks.accumdist;
mcd = MyStocks.macdiv;
stoch = MyStocks.fullstochosc;
bbands = MyStocks.bollingerbands;
nStocks = length(MyStocks);


figure(1)
clf
for i = 1:(ncols*nrows)
if i>nStocks, break, end
hgroup = stockchart(MyStocks(i),coptions,'subplot',[nrows ncols i]);
addoverlay(hgroup,bbands{i},'BBands')
hgroup = addindicator(hgroup,mcd{i},'centered','macd');
hgroup = addindicator(hgroup,accdist{i},'centered','A/D');
hgroup = addindicator(hgroup,stoch{i}(:,[3 4]),'banded',[20 80],'slowstoch');
end

image

back to top