Here's a suggestion to anyone who's losing ships to locked sectors - stop all of your autotraders and unlock any sectors then seta for a little bit, maybe a minute or two, then lock the sectors again, seta a bit more and then restart your UT's.
Here's how this script works: when you lock a sector it's stuffed into a global 2d array representing the universe. Any value in this array can be true (locked) or false (ignored). The script walks the universe grid, in order, from upper left to lower right and checks the global array to see if the current sector should be locked or not. If the sector should be locked then the script grabs a list of all stations in that sector and attempts to lock each of them with a perpetual task running on that station. The universe lock script will process the entire universe grid and then restart in the upper left corner - I refer to the universe lock task as the "rolling universe task" or "universe lock script", it's the coordinator for the whole system.
Here's the problem: if something has already requested that a station be locked then the perpetual lock task will fail and end. This means that the station won't be locked and that your traders are free to request a lock once the current locker releases it. If the lock target is extremely desirable (Full load of goods, or full demand for goods) then your traders will attempt to lock it and trade with it as a high priority. If they happen to have the station locked when the rolling universe task comes back to the sector then the cycle will start over.
There's one other possible problem: If GOD creates new stations then they're available for trade until the rolling task comes around again and locks them.
Here's why these problems still exist: I can make the rolling task roll around more often, unfortunately if I do that then there is a performance hit from processing sectors and stations more often. I tried to tune the script so that you wouldn't notice it running and I'm still convinced that decreasing the wait times isn't the best way to fix these issues.
I'll see if I can come up with some way to improve the locking mechanism, this was the best I could come up with when I wrote the script originally (no promises
it might take a while to improve the method).
edit: with gnasirator's improved UT script I don't think your ships will go into hostile territory to make any refuel transaction (ecells, drones, etc) - I __highly__ recommend using it in conjunction with my sector lock script.