flipflopper - I'm not going to give the code away - you may have to adapt these somewhat.

In my experience - what you need lies in the area of code for finding swing highs/lows.

Look around teh interweb - you will find better swing high/low finders that comes out of the box with TS