I'd like to backtest trends (mainly basic upward and downward trends), but I'm having trouble identifying trends with computer code. That is, I know a trend when I see it, but to exhaustively backtest a few thousand stocks over ~15 years, I need the computer to be able to identify it. For example, one possibility is to sort into deciles based on past return over some specified interval, with the top decile then categorized as the upward trending stocks and the bottom decile as the downward trending stocks. However, this is imprecise, and may even identify as upward trending a stock with one huge return followed by several below average returns. Any ideas on how I might proceed? Alternatively, does anyone know of software that does this type of backtesting?