Search code examples
rquantmod

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


Solution

  • "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.