EA ignoring open trades after editing and compiling the code, while trading live.

 
Please help, my EA ignores open trades every time i edit and compile the code, how can i prevent this from happening. I now even fear that should i switch the laptop, EA wont recognise open trades when i switch on the laptop on again. I use global variables to store the tickets values and unique magic numbers for each open trade. I even have code requiring the current position to be closed before opening an opposite position, but all of this, gets ignored after editing and compiling the code. How can i prevent this or what is causing it?. Please anyone.
 

Depends on how it is coded.

EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect / Position select loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.

On a network disconnection you might get ERR_NO_RESULT or ERR_TRADE_TIMEOUT. There is nothing to be done, but log the error, return and wait for a reconnection and a new tick. Then reevaluate. Was an order opened or is the condition still valid.

Reason: