Why do you need to analyse different time frames? My reading of the system description is that it is based on daily bars?

I set the bar period to 1440 and aligned the bars to midnight. I couldn't reproduce the results in the PDF you linked to. Nothing even close in fact!

Just to make your code a bit simpler:
I don't think you need the if statements around the setting of your buy and sell stops - they are covered in the if statements controlling your trade entries. Also, I don't think you need to limit the number of trades - you can only ever enter one trade in either direction at a time as a result of the strategy's rules.

Good luck! Will be interested to hear if you can reproduce those equity curves.