Indicator displays right values at launch but than wrong values

 

Hi i wrote this indicator starting from another more simple one...

When i lauch it or changing TF or refreshing everything is fine, but after that moment the result are wrong.

i've made a comparison of values between a freshly launched one and another one running for a while and results are different...

It seems like there are some dirty data some where...

thanks if someone can help me to understand what's wrong.

Files:
TSI-MT5-v3.mq5  48 kb