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
3
votes
3 answers

Plotting candlesticks with intraday data and adding moving averages, chartSeries or geom_candlestick

I am trying to plot candlesticks in R overlaid with moving averages, from my downloaded data for 30' SPY. I eventually want to plot one candlestick chart per day, with 14 day moving average overlaid, using a for-loop. Currently, I am not able to…
2
votes
1 answer

Is it possible to group by company when computing different technical indicators from the TTR package in R?

I am trying to compute various technical indicators that will be used to predict the stock price movement of around 100 stocks. For example, I want to calculate the Average True Range (ATR) for each of the companies in my time series, which I am…
hellberg30
  • 33
  • 5
2
votes
2 answers

Exponential moving average of a vector in R

I have a simple vector as follows: x = c(14.24, 13.82, 12.75, 12.92, 12.94, 13.00, 14.14, 16.28, 20.64, 17.64) I am trying to find the rolling EMA of this vector using the following function - library(TTR) y = EMA(x, 5) I am getting the result as…
Saurabh
  • 1,566
  • 10
  • 23
2
votes
1 answer

TTR runSD returns all NA

I think this came from an R/package update but now when I try to calculate the running standard deviation of a timeseries with an NA in it all I get is NA (current is R version 4.0.3, and TTR_0.24.2) How do I get: TTR::runSD(x = c(NA, 1:10), n = 1,…
Rafael
  • 3,096
  • 1
  • 23
  • 61
1
vote
1 answer

In TTR package, run function CTI failed

When I run function CTI(Close ,n=10), it show Caused by error:! cti_10 must be size 5550 or 1, not 5541. . How to fix it ? Thanks! library(tidyverse) library(TTR) data(ttrc) ttrc %>% mutate( cti_10 = CTI(Close ,n=10))
anderwyang
  • 1,801
  • 4
  • 18
1
vote
1 answer

R: trying to calculate RSI for a list of stocks

I am trying to add a data column with RSI values (from TTR package) to a data frame which contains stocks with historical price data. I am struggling when merging the data. So far i have this: library(BatchGetSymbols) library(TTR) first.date <-…
1
vote
1 answer

In R , is there any avaiable funcation like IFERROR formula in EXCEL

In R , is there any available function like IFERROR formula in EXCEL ? I want to calculate moving average using 4 nearest figures, but if the figures less than 4 in the group then using normal average. Detail refer to below code, the IF_ERROR is…
anderwyang
  • 1,801
  • 4
  • 18
1
vote
2 answers

donchian low in the TTR is incorrect plot

I am plotting the donchian high and low using tidy packages. the low value does not look correct. I am probably not calling the donchian function properly as the donchian_100_low is the highest value of the row. I dont know how to fix it. …
junkone
  • 1,427
  • 1
  • 20
  • 45
1
vote
1 answer

Passing subset of data.table columns to a function and adding the result back by reference in R

I have a data.table as follows - library(data.table) library(quantmod) dataTableTemp <- getSymbols('AAPL', auto.assign = FALSE) dt = data.table("date" = index(dataTableTemp), coredata(dataTableTemp)) > dt date AAPL.Open AAPL.High …
Saurabh
  • 1,566
  • 10
  • 23
1
vote
2 answers

Exponential moving average of just the last value of a vector in R

I have a simple vector as follows: x = c(14.24, 13.82, 12.75, 12.92, 12.94, 13.00, 14.14, 16.28, 20.64, 17.64) I have found the EMA of this vector using library(TTR) y = EMA(x, 5) and the result is [1] NA NA NA NA 13.33400 13.22267 13.52844…
Saurabh
  • 1,566
  • 10
  • 23
0
votes
2 answers

apply dplyr function to time series failed

There is time series ttrc_total , when applying the dplyr function group_by mutate ..., there are failures. Is there way to solve it? Thanks! library(TTR) library(tidyverse) data(ttrc) ttrc_total <- rbind(ttrc %>% mutate(category='A'), ttrc…
anderwyang
  • 1,801
  • 4
  • 18
0
votes
0 answers

R gives this error: "Error in hmax - lmin : non-numeric argument to binary operator" but doesn't after RStudio is restarted

While calculating SMI() function from TTR Package in R using RStudio, often this error is given: "Error in hmax - lmin : non-numeric argument to binary operator". But after simply closing RStudio - and saving all the workspace - and starting it…
Abdul Basit Khan
  • 646
  • 1
  • 6
  • 19
0
votes
1 answer

Why do Close and HLC have different methods to share data?

When I compare the 2 methods, SMA() needs close price as first parameter in xts format and DonchianChannel() needs HL in xts format. However the usage is Cl(mktdata) for SMA vs HLC(mktdata)[, 1:2] for DonchianChannel(). Why is this so? why cannot…
junkone
  • 1,427
  • 1
  • 20
  • 45
0
votes
1 answer

Error in using ATR as an indicator in quantstrat

Question 1: I am trying to use the ATR indicator in quantstrat. I am getting error Error in try.xts(HLC, error = as.matrix) : argument "HLC" is missing, with no default add.indicator(strategy = strategy.st, # correct name of…
junkone
  • 1,427
  • 1
  • 20
  • 45
0
votes
0 answers

How to rename column with tq_mutate

When I use tq_transmute, I am able to rename all the columns. When I use tq_mutate, only the first 2 columns are getting renamed. The last two columns remain as it is. Is this a limitation, or am I missing something to fix for tq_mutate? In the…
junkone
  • 1,427
  • 1
  • 20
  • 45
1
2