#' Ichimoku
#'
#' @param HLC xts object that contains High-Low-Close prices
#' @param nFast fast period of
#' @param nMed medium period of days
#' @param nSlow slow period of days
#'
#' @import xts
#' @import quantmod
#' @import TTR
#'
#' @return
#' @export
#'
#' @examples ichimoku(price_data, nFast = 9, nMed = 26, nSlow = 52)
ichimoku <- function(HLC, nFast = 9, nMed = 26, nSlow = 52) {
conversionLine <- (runMax(Hi(HLC), nFast)+runMin(Lo(HLC), nFast))/2
baseLine <- (runMax(Hi(HLC), nMed)+runMin(Lo(HLC), nMed))/2
spanA <- lag((conversionLine+baseLine)/2, nMed)
spanB <- lag((runMax(Hi(HLC), nSlow)+runMin(Lo(HLC), nSlow))/2, nMed)
laggingSpan <- lag(Cl(HLC), nMed)
out <- cbind(turnLine=conversionLine, baseLine=baseLine, spanA=spanA, spanB=spanB, laggingSpan=laggingSpan )
colnames(out) <- c("conversionLine", "baseLine", "spanA", "spanB", "laggingSpan")
return (out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.