Technical Analysis using R Software - Calculating Standard Pivot Points - Support Resistance Levels
1. Technical Analysis using R
Software
Calculating Standard Pivot Points - Support
Resistance Levels using quantmod package
Rajesh Prabhakar Kaila
http://facultyofbusinessanalytics.blogspot.in/
2. Introduction to Pivot Points
Technical Analysts often refer to Pivots Points that can be defined as a
point at which a major price movement is expected to occur.
Pivot Points basically define directional price movement or support and
resistance levels.
Pivot Points are calculated using the prior period's high, low and close
price of the stock, commodity or currency and based on which a future
support and resistance level is identified.
Pivot Points can be considered as predictive or leading indicators.
Pivot points are to be calculated on daily basis.
3. Pivot Points – Time Frames
Pivot Points for 1, 5, 10 and 15 minute charts use the prior day's
high, low and close.
Pivot Points for 30 and 60 minute charts use the prior week's high,
low and close. These calculations are based on calendar weeks.
Pivot Points for daily charts use the prior month's data. Pivot Points
for current month would be based on the high, low and close for
previous month.
Once Pivot Points are fixed, they do not change and remain same
during the relevant time frame.
Source: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:pivot_points
4. Standard Pivot Points Calculation
Standard Pivot Points also called the five-point system as it involves five
different points. ( Average Point + S1+S2+R1+R2 ).
Calculation is based on the simple average of previous day's high, low and
close prices combined with two support levels (S1 & S2) and two
resistance levels (R1 & R2) to derive a pivot point. The equations are as
follows:
R2 = P + (H - L) = P + (R1 - S1)
R1 = (P x 2) - L
P = (H + L + C) / 3
S1 = (P x 2) - H
S2 = P - (H - L) = P - (R1 - S1)
Here, "S" represents the support levels, "R" the resistance levels and "P"
the pivot point. High, low and close prices are represented by the "H," "L"
and "C," respectively.
5. R Code for Standard Pivot Points
getSymbols('INFY.BO',src='yahoo') # Data downloaded from January 1st 2007
till the current previous day
INFY=INFY.BO['2015-01-01::2015-05-31'] # Choosing Data from January 1st
2015 till May 31st 2015
head(INFY) # First Six Lines of Data
chartSeries(INFY) # Candlestick Chart of Infosys
center <- xts(rowSums(HLC(INFY))/3,order.by=index(INFY)) # Average of High,
Low & Close Price (H+L+C/3)
head(center) # First Six Lines of Data
R1 <- (2*center)-Lo(INFY) # First Resistance (R1) = (2*P) - Low
S1 <- (2*center)-Hi(INFY) # First Support (S1) = (2*P) - High
R2 <- center + (R1 - S1) # Second Resistance (R2) = P + (R1-S1)
S2 <- center - (R1 - S1) # Second Support (S2) = P - (R1- S1)
ret <- cbind(center,R1,R2,S1,S2) # Combining all Calculations in adjacent
columns
6. R Code for Standard Pivot Points
colnames(ret) <- c('center','R1','R2','S1','S2') # Column Names
dat = cbind(INFY,ret) # Combining both the sheets or files
head(dat) # First Six Lines of Data
write.csv(dat,"Datasupres.csv") # Saving a copy as CSV file
chartSeries(INFY) # Candlestick Chart of Infosys
addTA(dat$S1, on=1, col='lightblue') # Adding Support1 Line to Candlestick
Chart
addTA(dat$S2, on=1, col='blue') # Adding Support2 Line to Candlestick Chart
addTA(dat$R1, on=1, col='pink') # Adding Resistance1 Line to Candlestick
Chart
addTA(dat$R2, on=1, col='red') # Adding Resistance2 Line to Candlestick
Chart