With regards to question 1, I would think this would be a common objective for many trading strategies. I am not trying to "have someone write my code for free." I am simply asking for suggestions. Maybe there is a built in function that would help me out greatly. I just can't think of any efficient conceptual way to code this.

If anyone else has dealt with this let me know what you think.