How To Calculate Support and Resistance levels in R?

by darrion.kuhn , in category: Third Party Scripts , 5 months ago

How To Calculate Support and Resistance levels in R?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , 5 months ago

@darrion.kuhn 

Support and resistance levels can be calculated using various technical analysis tools in R, such as moving averages, pivot points, and trend lines. Here is a general guideline on how to calculate support and resistance levels using moving averages in R:

  1. Load the necessary libraries:
1
2
library(quantmod)
library(TTR)


  1. Get historical price data: You will need historical price data for the stock or asset you are analyzing. You can use the getSymbols function from the quantmod package to download historical price data from sources like Yahoo Finance or Google Finance.
1
getSymbols("AAPL", from = "2019-01-01", to = "2020-01-01", src = "yahoo")


  1. Calculate moving averages: You can calculate different moving averages, such as the simple moving average (SMA) or the exponential moving average (EMA), to identify potential support and resistance levels.
1
2
AAPL$SMA20 <- SMA(Cl(AAPL), n = 20)
AAPL$EMA50 <- EMA(Cl(AAPL), n = 50)


  1. Plot the moving averages: Visualize the moving averages on a price chart to identify potential support and resistance levels.
1
2
3
chart_Series(AAPL)
add_TA(AAPL$SMA20, on = 1, col = "blue")
add_TA(AAPL$EMA50, on = 1, col = "red")


  1. Identify support and resistance levels: Support levels are usually identified as areas where the price tends to bounce off or reverse its direction. Resistance levels are areas where the price struggles to break above. By observing how the price interacts with the moving averages, you can determine potential support and resistance levels.


Keep in mind that support and resistance levels are not fixed and may change over time as market conditions evolve. It is recommended to combine moving averages with other technical analysis tools to confirm your findings.