I feel a bit shamed for having made such stupid mistake, replacing the while with the if fixed it.

A bit off topic, but would like to thank you for writing Financial Hacker, really liked every post.

Will keep reading you and improving my Zorro scripts.

Thank you very much jcl.