I don't use quantmod
, but you can aggregate the data using R's tapply
.
Assume you have your tick data, and these are sorted in time. Let's make up some data.
ticks <- cumprod(1 + rnorm(100020, sd = 0.001))
Compute the number of bars.
n <- ceiling(length(ticks)/500)
bars <- rep(1:n, each = 500)[seq_along(ticks)]
Compute open, high, low close for each bar and combine them into a matrix.
ohlc.list <- tapply(ticks, bars,
function(x) c(x[1], max(x), min(x), x[length(x)]))
ohlc <- do.call(rbind, ohlc.list)
colnames(ohlc) <- c("open", "high", "low", "close")
You may now process these bars as you like; perhaps attach a timestamp to each bar, and plot them.