Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R support resistance levels as probability distribution

Tags:

r

quantmod

TTR has some excellent TA indicators. Is there a package or function that calculates and charts different types of Support and resistance levels? Preferably a probability distribution for the likely support and resistance levels

like image 783
adam.888 Avatar asked Jan 16 '23 09:01

adam.888


2 Answers

Here's an example to follow up on my comment.

Calculate pivots using monthly data. Each month, use the Support and Resistance calculated from the previous month's data. (Of course, it doesn't have to be monthly pivots with daily data. You could use daily pivots, and an intraday price series)

library(quantmod)
getSymbols("SPY", from="2010-05-01", to="2012-06-15")
mSPY <- to.monthly(SPY, drop.time=TRUE)
# pivots() is excluded from the TTR build because it uses quantmod functions,
# but you can still get it from GitHub by running:
#source("https://raw.githubusercontent.com/joshuaulrich/TTR/master/R/pivots.R")
piv <- lag(pivots(mSPY, lagts=FALSE))
#merge, and fill forward pivot values so that there is a value for each day
dat <- cbind(SPY, piv)
dat[, 7:11] <- na.locf(dat[, 7:11])
chartSeries(OHLC(SPY), theme='white')
addTA(dat$S1, on=1, col='lightblue')
addTA(dat$S2, on=1, col='blue')
addTA(dat$R1, on=1, col='pink')
addTA(dat$R2, on=1, col='red')

That will produce:

enter image description here

Donchian Channels could also be seen as support and resistance

chartSeries(OHLC(SPY), theme='white')
dc <- lag(DonchianChannel(cbind(Hi(SPY), Lo(SPY))))
addTA(dc$low, on=1, col='blue')
addTA(dc$high, on=1, col='red')

enter image description here

like image 136
GSee Avatar answered Jan 30 '23 19:01

GSee


Most of the technical analysis indicators in quantmod come from the TTR package, which I wrote. I did not include subjective indicators like support/resistance lines. That said, quantmod has an addLines function you can use.

library(quantmod)
getSymbols("SPY", from="2012-01-01", to="2012-06-15")
chartSeries(SPY, TA="addLines(h=c(134,141))", theme="white")

Which produces:

chartSeries with support/resistance lines

like image 34
Joshua Ulrich Avatar answered Jan 30 '23 19:01

Joshua Ulrich