Questions tagged [ttr]

R pakcage: Technical Trading Rules

TTR: Technical Trading Rules - A collection of over 50 technical indicators for creating technical trading rules. The package also provides fast implementations of common rolling-window functions, and several volatility calculations.

27 questions
0
votes
2 answers

In Quantstrat I can only add up to 7 indicators with the add.indicator() Function. How can I include more indicators (columns in the mktdata object?

The error message I receive when I add more than 7 indicators to the strategy and use the applyIndicators function: Error in (function (HLC, n = 20, maType, c = 0.015, ...) : Price series must be either High-Low-Close, or Close/univariate. In…
0
votes
2 answers

Apply running average by year for all columns in R

I need to calculate the running average by year for each column. My data example: dat <- data.frame(yr = c(1980, 1980, 1980, 1980, 1980, 1981, 1981, 1981, 1981, 1981, 1982, 1982, 1982, 1982, 1982), data1 = c(-10.16, -7.48, -3.31, -6.04, -11.68,…
Indrute
  • 115
  • 10
0
votes
1 answer

RSI is different in R vs Yahoo Finance/TradingView

The RSI calculated in R is different than that I see in Yahoo-Finance. Yahoo-Finance documentation says it uses SMA and close. I done the same in R but the values don't match. I am not sure which one to trust. I tried both close & Adjusted…
Aman J
  • 1,825
  • 1
  • 16
  • 30
0
votes
1 answer

Lagged exponential moving average of a vector

Given a simple vector of 82 observation x = c(102, 104, 89, 89, 76, 95, 88, 112, 81, 101, 101, 104, 94, 111, 108, 104, 93, 92, 86, 113, 93, 100, 92, 80, 92, 126, 102, 109, 104, 95, 84, 81, 103, 83, 103, 83, 58, 109, 89, 93, 104, 104, 123, 104, 93,…
0
votes
0 answers

Quantstrat throwing error with my Linear Regression Curve function

I am getting the following error when I run the code below. "Error in if (inherits(sret$indicators, "xts") & nrow(mktdata) == nrow(sret$indicators)) { : argument is of length zero". My guess is I am missing something in my Linear Regression Curve…
0
votes
1 answer

R Finding the RSI on a subset

I am using the following code to find the RSI (Relative Strength Index) and DEMA (double exponential moving average) of a stock. library(quantmod) library(TTR) getSymbols("AAPL") chartSeries(AAPL, TA=NULL) data=AAPL[,4] AAPL$rsi =…
Saurabh
  • 1,566
  • 10
  • 23
0
votes
1 answer

Why am I getting an error with TTR rollSFM loading a CSV file

I'm trying to plot a rolling linear regression, but get the following error: Error in if (any(by < 0L) || any(by > nc)) stop("'by' must match numbers of columns") : missing value where TRUE/FALSE needed The relevant code is: library(TTR) mydata…
0
votes
1 answer

EMA with multiple periods in R

I'm trying to calculate multiple EMA for S&P 500 with different underlying periods. #get stock data library(quantmod) getSymbols("^GSPC", src="yahoo", from="2020-01-01", to="2020-09-30") SP500 <- GSPC[,"GSPC.Close"] I know how to do it manually,…
Flo2020
  • 31
  • 3
0
votes
1 answer

Cumulative return of positive and negative numbers

I am trying to find the cumulative return of the following 4 vectors using the function cummulative_return (given below) but the result is not as expected. library(TTR) # ROC function a = c(-1000,-2000,-3000,-4000,-5000,-6000,-7000,-8000) b =…
Saurabh
  • 1,566
  • 10
  • 23
0
votes
2 answers

How can I plot the regression lines analysis in R

I want to plot regression lines in R for technical analysis. First, I regress the price on the date and I get the main regression line. However, also, I need lines that correspond to (Main regression line +- 2*standard deviation). Do you know how I…
Enes
  • 59
  • 5
0
votes
0 answers

TTR:StockSymbols() - Receiving stock symbols error

This issue has happened multiple times now and I don't know how to fix it. Has anyone dealt with this error in the TTR package? library('TTR') symbols <- TTR::stockSymbols() Fetching AMEX symbols... Error in file(file, "rt") : cannot open the…
nak5120
  • 4,089
  • 4
  • 35
  • 94
-2
votes
2 answers

Swing high and low from Pine to R

I am trying to translate a Swing High and Low function from Pine to R, and I cannot really get the logic behind the Pine code. Basically, this function loops over a time series database of high and low prices, and yields: A swing high: as the…
Camilo
  • 153
  • 7
1
2