getting the trend elements and storing

Pasted the code at the end of the file.