Eka
Eka

Reputation: 15010

Trend up and down function for R

I am using quantmod for backtesting and have a column with SMA values

sma<-SMA(Cl(symbol),20)

I want to know whether any trend up or down fucntion is available for R to find out the trend of sma

eg. trendup(sma) gives TRUE if sma is trending upwards or else false

Upvotes: 2

Views: 382

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176648

"Trending" is not well defined. You must choose thresholds for magnitude and timespan. A simple trend indicator would be any magnitude for 1 period: sign(diff(sma)).

See ?TTR::ADX and its See Also section for some different ways to measure trend.

Upvotes: 3

Related Questions