quantmod chartSeries繪圖

theme = chartTheme(“white”),
TA = c(addBBands(),

chartSeries {quantmod} 
Create Financial Charts


Charting tool to create standard financial charts given a time series like object. Serves as the base function for future technical analysis additions. Possible chart styles include candles, matches (1 pixel candles), bars, and lines. Chart may have white or black background.

reChart allows for dynamic changes to the chart without having to respecify the full chart parameters.


 type = c(“auto”, “candlesticks”, “matchsticks”, “bars”,”line”), 
 subset = NULL,
 show.grid = TRUE, 
 name = NULL,
 time.scale = NULL,
 log.scale = FALSE,
 TA = ‘addVo()’,
 line.type = “l”,
 bar.type = “ohlc”,
 theme = chartTheme(“black”),
 layout = NA,
 major.ticks=’auto’, minor.ticks=TRUE,
 up.col,dn.col,color.vol = TRUE, multi.col = FALSE,

reChart(type = c(“auto”, “candlesticks”, “matchsticks”, “bars”,”line”), 
 subset = NULL,
 show.grid = TRUE, 
 name = NULL,
 time.scale = NULL,
 line.type = “l”,
 bar.type = “ohlc”,
 theme = chartTheme(“black”),
 major.ticks=’auto’, minor.ticks=TRUE,
 up.col,dn.col,color.vol = TRUE, multi.col = FALSE,

an OHLC object — see details
style of chart to draw
xts style date subsetting argument
display price grid lines?
name of chart
what is the timescale? automatically deduced (broken)
should the y-axis be log-scaled?
a vector of technical indicators and params, or character strings
TA delimiter for TA strings
type of line in line chart
type of barchart — ohlc or hlc
a chart.theme object
if NULL bypass internal layout
where should major ticks be drawn
should minor ticks be draw?
override y-scale
should plot be drawn
up bar/candle color
down bar/candle color
color code volume?
4 color candle pattern
additional parameters

Currently displays standard style OHLC charts familiar in financial applications, or line charts when not passes OHLC data. Works with objects having explicit time-series properties.

Line charts are created with close data, or from single column time series.

The subset argument can be used to specify a particular area of the series to view. The underlying series is left intact to allow for TA functions to use the full data set. Additionally, it is possible to use syntax borrowed from the first and last functions, e.g. ‘last 4 months’.

TA allows for the inclusion of a variety of chart overlays and tecnical indicators. A full list is available from addTA. The default TA argument is addVo() — which adds volume, if available, to the chart being drawn.

theme requires an object of class chart.theme, created by a call to chartTheme. This function can be used to modify the look of the resulting chart. See chart.theme for details.

line.type and bar.type allow further fine tuning of chart styles to user tastes.

multi.col implements a color coding scheme used in some charting applications, and follows the following rules:

grey => Op[t] < Cl[t] and Op[t] < Cl[t-1]

white => Op[t] < Cl[t] and Op[t] > Cl[t-1]

red => Op[t] > Cl[t] and Op[t] < Cl[t-1]

black => Op[t] > Cl[t] and Op[t] > Cl[t-1]

reChart takes any number of arguments from the original chart call — and redraws the chart with the updated parameters. One item of note: if multiple color bars/candles are desired, it is necessary to respecify the theme argument. Additionally it is not possible to change TA parameters at present. This must be done with addTA/dropTA/swapTA/moveTA commands.


Returns a standard chart plus volume, if available, suitably scaled.

If plot=FALSE a chob object will be returned.


Most details can be fine-tuned within the function, though the code does a reasonable job of scaling and labelling axes for the user.

The current implementation maintains a record of actions carried out for any particular chart. This is used to recreate the original when adding new indicator. A list of applied TA actions is available with a call to listTA. This list can be assigned to a variable and used in new chart calls to recreate a set of technical indicators. It is also possible to force all future charts to use the same indicators by calling setTA.

Additional motivation to add outlined candles to allow for scaling and advanced color coding is owed to Josh Ulrich, as are the base functions (from TTR) for the yet to be released technical analysis charting code.

Many improvements in the current version were the result of conversations with Gabor Grothendieck. Many thanks to him.

Like what you read? Give Steven Wang a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.