If you change StartDate = 20090901; to StartDate = 20090101; you get a BADFREE2: TR as a bonus at Bar # 23993.

How could such a simple script go so wrong?