why orders closed on vps terminal after re-synchronization?

 

I am hoping somebody could find the problem. i have open orders on the vps side. the ea is working as it should be. the problem is when i re-sync the terminal, all open orders get closed automatically. here is the ea  that i used to make my own ea. the basic structure  for the condition and the way the open orders are closed is almost the same. my guess is that it has something to do with Global Variable and the OrderHistory being used as closing conditions. hope someone could help me.

Files: