Open knshetty opened 9 years ago
I don't use it for visualization. I use it as a trading indicator. It would also mean having to extend the xts object, which I'm not quite sure how to do.
On Sun, Dec 14, 2014 at 8:22 PM, Nash notifications@github.com wrote:
Using the ichimoku indicator https://github.com/IlyaKipnis/IKTrading/blob/master/R/ichimoku.R, I am attempting to plot Ichimoku Cloud, with the below implementation:
require(quantmod) require(IKTrading) getSymbols('IBM', src='google', from='2014-04-01') ibm_ic = ichimoku(IBM) ibm_icPlot <- ibm_ic[,1:5] chart.TimeSeries(ibm_icPlot, legend.loc = "topleft")
After running the above code, all the five lines are rendered in the Chart (i.e. turning line, base line, Span A, Span B, plotSpan), here's the screenshot of my RStudio with the plot:
Well, the problem is with the 'Span A' & 'Span B' lines (i.e. future cloud), which are not projected ('nMed=26') into the future. This projection is very important aspect of visualizing an Ichimoku Cloud in its entirety. Any suggestion on how to make the ichimoku indicator https://github.com/IlyaKipnis/IKTrading/blob/master/R/ichimoku.R to plot the future cloud? Or is there something wrong in the above implementation?
— Reply to this email directly or view it on GitHub https://github.com/IlyaKipnis/IKTrading/issues/3.
If you are using the ichimoku indicator as a pure trading indicator, the future cloud formation still needs to be inclusive. Because the future cloud helps to determine the market sentiment (i.e. a measure of equilibrium according to Goichi Hosoda), hence this future cloud can signal potential trend reversals that is either bullish or bearish, which can be a viable flag in an Ichimoku based Algo. A brief theory and application of pairing the 'SpanA' & 'SpanB' lines can be found here.
Well, this is my attempt to render the 'Span A' & 'Span B' lines (i.e. future cloud). Now, 'Span A' & 'Span B' lines are projected 26 periods into the future. This was achieved without any data-loss considering how the 'Span A' & 'Span B' data-points are calculated at present in the ichimoku indicator, I presume this data-loss is intentional for 'Span A' & 'Span B'... Is it?
Here's the implementation code & screenshot of the plot:
require(quantmod)
require(IKTrading)
getSymbols('IBM', src='google', from='2014-04-01')
ProjectTimeseriesToFuture <- function(dataset, projectionPeriod) {
extendedIndex <- timeBasedSeq(paste(end(dataset),end(dataset),sep="/"), length.out=projectionPeriod+1)
out <- merge(dataset, xts(, extendedIndex[2:length(extendedIndex)]))
return(out)
}
ichimoku <- function(HLC, nFast=9, nMed=26, nSlow=52) {
turningLine <- (runMax(Hi(HLC), nFast)+runMin(Lo(HLC), nFast))/2
baseLine <- (runMax(Hi(HLC), nMed)+runMin(Lo(HLC), nMed))/2
spanA <- lag(ProjectTimeseriesToFuture((turningLine+baseLine)/2, nMed), nMed)
spanB <- lag(ProjectTimeseriesToFuture((runMax(Hi(HLC), nSlow)+runMin(Lo(HLC), nSlow))/2, nMed), nMed)
plotSpan <- lag(Cl(HLC), -nMed)
out <- cbind(turnLine=turningLine, baseLine=baseLine, spanA=spanA, spanB=spanB, plotSpan=plotSpan)
colnames(out) <- c("turnLine", "baseLine", "spanA", "spanB", "plotLagSpan")
return (out)
}
ibm_ic = ichimoku(IBM)
ibm_icPlot <- ibm_ic[,1:5]
chart.TimeSeries(ibm_icPlot, legend.loc = "topleft")
Comments & suggestions are welcome :)
Looks good, actually. Thanks a lot =).
On Mon, Dec 15, 2014 at 10:03 PM, Nash notifications@github.com wrote:
If you are using the ichimoku indicator https://github.com/IlyaKipnis/IKTrading/blob/master/R/ichimoku.R as a pure trading indicator, the future cloud formation still needs to be inclusive. Because the future cloud helps to determine the market sentiment (i.e. a measure of equilibrium according to Goichi Hosoda), hence this future cloud can signal potential trend reversals that is either bullish or bearish, which can be a viable flag in an Ichimoku based Algo. A brief theory and application of pairing the 'SpanA' & 'SpanB' lines can be found here http://www.kumotrader.com/ichimoku_wiki/index.php?title=Ichimoku_components#Senkou_Span_A.
Well, this is my attempt to render the 'Span A' & 'Span B' lines (i.e. future cloud). Now, 'Span A' & 'Span B' lines are projected 26 periods into the future. This was achieved without any data-loss considering how the 'Span A' & 'Span B' data-points are calculated at present in the ichimoku indicator https://github.com/IlyaKipnis/IKTrading/blob/master/R/ichimoku.R, I presume this data-loss is intentional for 'Span A' & 'Span B'... Is it?
Here's the implementation code & screenshot of the plot:
require(quantmod) require(IKTrading) getSymbols('IBM', src='google', from='2014-04-01')
ProjectTimeseriesToFuture <- function(dataset, projectionPeriod) { extendedIndex <- timeBasedSeq(paste(end(dataset),end(dataset),sep="/"), length.out=projectionPeriod+1) out <- merge(dataset, xts(, extendedIndex[2:length(extendedIndex)])) return(out) }
ichimoku <- function(HLC, nFast=9, nMed=26, nSlow=52) { turningLine <- (runMax(Hi(HLC), nFast)+runMin(Lo(HLC), nFast))/2 baseLine <- (runMax(Hi(HLC), nMed)+runMin(Lo(HLC), nMed))/2 spanA <- lag(ProjectTimeseriesToFuture((turningLine+baseLine)/2, nMed), nMed) spanB <- lag(ProjectTimeseriesToFuture((runMax(Hi(HLC), nSlow)+runMin(Lo(HLC), nSlow))/2, nMed), nMed) plotSpan <- lag(Cl(HLC), -nMed)
out <- cbind(turnLine=turningLine, baseLine=baseLine, spanA=spanA, spanB=spanB, plotSpan=plotSpan) colnames(out) <- c("turnLine", "baseLine", "spanA", "spanB", "plotLagSpan") return (out)
}
ibm_ic = ichimoku(IBM) ibm_icPlot <- ibm_ic[,1:5] chart.TimeSeries(ibm_icPlot, legend.loc = "topleft")
Comments & suggestions are welcome :)
— Reply to this email directly or view it on GitHub https://github.com/IlyaKipnis/IKTrading/issues/3#issuecomment-67105799.
Hi, @knshetty
When I try your code, I get the following error: Error in lag(Cl(HLC), -nMed) : n must be a single positive integer
Wonder where did I go wrong?
@debsush,
I found the issue lied in the order which you load dplyr package and the xts package. See: https://github.com/joshuaulrich/xts/issues/131
The quickest fix I found to be loading xts after or not loading dplyr if you don't have to.
Hope that helps!
@Esturban
Many thanks. This was most helpful.
Using the ichimoku indicator, I am attempting to plot Ichimoku Cloud, with the below implementation:
After running the above code, all the five lines are rendered in the Chart (i.e. turning line, base line, Span A, Span B, plotSpan), here's the screenshot of my RStudio with the plot:
Well, the problem is with the 'Span A' & 'Span B' lines (i.e. future cloud), which are not projected ('nMed=26') into the future. This projection is very important aspect of visualizing an Ichimoku Cloud in its entirety. Any suggestion on how to make the ichimoku indicator to plot the future cloud? Or is there something wrong in the above implementation?