reliable way to check for disconnetion/ switch account/ reconnection

 
My script is giving me errors when I change accounts/reconnect.

Then I tried IsConnect + a time delay everytime a Disconnect is encountered. It worked fine until I encountered another problem.

Sometimes, switching between accounts would not change IsConnected()...

Is there othere ways? Is "HistoryTotal()" an effective way to check if I am already connected??

HistoryTotal() does not detect "disconnect"....