Need Ideas On Programming - Trend Analysis

 

I'm trying to figure out the best way to have a program recognize the peaks and valleys on most charts? Are there any completed indicators that already identify the high points and low points in a chart over a specific period of time?

The problem is how to determine what the time period is for it to look for new peaks and new low points. Any ideas on how to overcome this would be appreciated. Thanks!