EA which closes down the trade if metatrader closes down and the reopens

 
Hi I am using an EA which has a problem in the coding. If MetaTrader is closed down or cut off whilst the EA is running and a trade has been open, then when MetaTrader is reopned the EA closes the trade out. This is only a problem is MetaTrader losses conection and reopens itself automatically. Does anyone know how to either stop MetaTrader reopening automatically or point me in the right direction to get the coding corrected so this problem is solved.
 
we need to c the code