Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Also I’m not to much into Technical Indicators and Chart-Analysis during system development it is sometimes handy to visualize your buy and selllimits in a chart.

The quantmod package provides a nice charting environment and you can select from a bunch of predefined indicators.

However what I would like to have is to display my buy and selllimits in my chart.

This can be achieved using addTA but before we can display the TA we need to write some code.

Just as example I’m using some indicators I have added to the yahoo OHLC Data

for(symbol in portfAsymbols){
x=get(symbol)
tmpATR <- ATR(x[,c(2,3,4)],atrvalue,maType=EMA,wilder=TRUE)
tmpSAR <- SAR(x[,c(2,3)],accel=c(0.02,0.2))
tmpBB <-BBands(x[,c(2,3,4)],n=20,sd=2,maType="SMA")
x$atrind <- tmpATR$atr
x$adxind <-tmpADX$ADX
x$sar<-tmpSAR assign(symbol,x) } Now I’m defining my buylimit by adding or subtracting the ATR to yesterdays CLOSE. atrpos=atrvalue + 2 buy = matrix (nrow = n, ncol = 1) sell = matrix (nrow = n, ncol = 1) for( i in atrpos:n ) { buy[i,]=as.numeric(Cl(x[i-1,]))+ as.numeric(round(x$atrind[i-1,],2))
sell[i,]=as.numeric(Cl(x[i-1,]))- as.numeric(round(x\$atrind[i-1,],2))

}

And finally we can now display this buy and selllimit on the chart.

here is the result